JavaScript Function Syntax
A JavaScript function is defined with:
- The keyword: function
- A name -- function names can contain letters, digits, underscores, and dollar signs (same rules as variables).
- Parentheses () -- which may include parameter names separated by commas: (parameter1, parameter2, ...).
- Then curly brackets {}, which contain the code to be executed by the function.
function name(parameter1, parameter2, parameter3) {
code to be executed
}
- Function parameters are the names listed in the function definition
- Function arguments are the real values received by the function when it is invoked
- Inside the function, the arguments behave as local variables
A Function is much the same as a Procedure or a Subroutine, in other programming languages.