The function definition of JS has the following two kinds of ways:
(1) A typical function declaration
function Slide (arguments) {
//...code
}
(2) Defining a function as a function expression
var slide = function (arguments) {
//...code
}
Although the above two ways are logically equivalent, there is a slight difference:
Difference One: The function in example one is loaded into the scope before the execution of the code, and example two is defined when the code executes to that line;
Difference Two: The function declaration assigns a name to the function, and the function expression creates an anonymous function and assigns the anonymous function to a variable;
Look at 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 expression is defined
var factorial = function (num) {
// ... code
}
//...code
console.log (anotherfactorial);//Output function () {}, anonymous function
The above JS function to define the way the difference is small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.