A comprehensive understanding of anonymous functions in JS
- 2021-07-01 06:19:47
- OfStack
1. Declare:
1. Normal function declaration:
// Normal function declaration
function foo(p1, p2){
return p1+p2;
}
2. Anonymous function declaration:
// Anonymous function declaration
var foo= function(p1, p2){
return p1+p2;
}
2. Return value:
The return value of the anonymous function is a reference to an Function object.
3. Meaning:
The anonymous function code above means assigning a reference to the Function object to the variable foo.
4. Similarities:
After generating a function body without a name (Function object), give it another name.