Differences between JS function definitions and js function definitions
There are two methods to define JS functions:
(1) typical function declaration
Function slide (arguments) {//... code}
(2) define a function in the form of a function expression
Var slide = function (arguments) {//... code}
Although the above two methods are logically equivalent, they are slightly different:
Difference 1: Functions in Example 1 will be loaded into the scope before code execution, while in example 2, they will be fixed only when the code is executed to that line;
Difference 2: The function declaration will specify a name for the function, and the function expression is to create an anonymous function, and then assign this anonymous function to a variable;
Take the following example:
Function factorial (num) {if (num <= 1) {return 1;} else {return num * arguments. callee (num-1) ;}}var anotherFactorial = factorial; factorial = null; console. log (anotherFactorial); // output factorial () {}. If a function name is defined as a function expression, var factorial = function (num ){//... code }//... codeconsole. log (anotherFactorial); // output function () {}, anonymous function
The differences between the above JS function definition methods are all the content shared by the editor. I hope to give you a reference and support for the help house.