In JavaScript, functions are objects, and programs can manipulate them arbitrarily. For example, JavaScript can assign a function to a variable, or pass it as a parameter to other functions, and you can set properties on them or even invoke their methods.
function definition
The general function definition has the following forms:
- Function declaration method
Note: The function declaration statement is "advanced" to the top of the script, so you can call the function before the code is defined.
- Function Assignment method (can be defined as anonymous function)
Note: The left parenthesis on the left side of the function is required because if you do not write the opening parenthesis, the JavaScript interpreter parses the keyword function into a declaration statement . With the opening parenthesis, the JavaScript interpreter correctly resolves it to a function-definition expression .
Javascript (Declaration, assignment)