Function expression in javascript
Functions in JavaScript are actually equivalent to methods in java, but the format of method definition is different. However, java and JavaScript are completely different languages. If you don't think either of them has a java, you think they have a relationship. In fact, they have nothing to do with them. The following describes the function expression in JavaScript.
I. function declaration method
A. Basic syntax
Function keywords
1,
Function Name ([parameter 1], [parameter 2]...) {
Function body
[Retrun] // Return Value
}
B. literal definition form (anonymous function)
2,
Var variable = function ([parameter 1], [parameter 2]...) {
Function body
[Retrun] // Return Value
}
C. Declare it as an object
3,
Var variable = new Function ([parameter 1], [parameter 2]..., Function body );
I personally think that the first function declaration method is better because the first method is intuitive and the code is readable.
Ii. function call method:
A. Function Name () and variable name ();
B. (function () {alert (who I am );})();
Iii. Differences between the three declarative Methods
1. If the names of the two functions are the same, the subsequent functions will overwrite the previous functions.
2. Functions declared in basic syntax are loaded into the memory in advance during code execution for future use,
However, a function named literally is assigned a value only when it is executed.
3. When using and calling functions in different <script> </script> blocks, you should first define them and then execute them. It is like if you go to a restaurant to eat, you must first serve dishes, if you want to eat again, you cannot eat food first. It is not scientific.