Functions are one of the fundamental building blocks in JavaScript. To use a function, you must define it somewhere in the scope in which you would like to call it.
A function statement consists of the “function” keyword, followed by the: name of the function; a list of parameters to the function, closed in by parentheses and separated by commas; the statements that define the function, enclosed in curly brackets.
Below is a visual summary of a basic function:
The function “square” takes on parameter, called “number”. The function “square” consists of one statement that says to return the parameter of the function (“number” * “number”). The statement “return” specifies the value returned by the function.
Hi Angelo, it is important to understand how functions work. Functions allow programmers to simplify their codes into more manageable components. You did a good job explaining how functions work, and the picture you included definitely helped.