Method one: var foo = function () {//code} method two: function foo () {//code} method one: Foo is undefined when the function execution context starts executing code, and the execution of var foo = func tion () {} This sentence, Foo will get the assignment, method two: When entering the function execution context to start executing code, Foo is already a function.once in the execution context (before executing the code), VO (Variable object) is populated with some properties:Formal parameters of the function (when entering the function execution context)
A property of a variable object whose property name is the name of the formal parameter, whose value is the value of the argument, and for a parameter that is not passed, its value is the undefined function declaration (functiondeclaration, FD)--a property of the variable object whose property name and value are created by the function object. If the variable object already contains a property of the same name, replace its value variable declaration (var,variabledeclaration)-a property of the variable object whose property name is the variable name and its value is undefined; If the variable name is the same as the function name already declared or the parameter name of the function, the existing property is not affected.Declarations, Names, and hoisting (Declaration and variable elevation)In JavaScript, a name enters a scope in one of four basic ways:-Language-defined:all scopes is, by default, given the N Ames this and arguments.-formal parameters:functions can has named formal parameters, which is scoped to the body of T Hat function.-function Declarations:these is of the form function foo () {}.-Variable Declarations:these take the form var foo;. One approach to anonymous functions, which we see in jquery fragments, is to use () to enclose the anonymous function, followed by a pair of parentheses (including the parameter list).parentheses can combine our expressions and each block, that is, each pair of parentheses, has a return value. This return value is actually the return value of the expression in parentheses. So, when we enclose the anonymous function with a pair of parentheses, the actual parentheses return is the function object of the anonymous functions. Therefore, the parenthesis pair plus the anonymous function is like a named function where we get its reference position. So if you add a parameter list after the reference variable, the invocation form of the normal function is implemented. Under Firefox, Safari, Chrome, and opera, you can use name to get the function name. The Name property of the anonymous function is an empty string. This is wrong, do not do so AH!! if (condition) {//The purpose is to determine and then determine the operation of the function
function Sayhi () {alert ("hi!");}
} else {
function
Sayhi () {///But most browsers will return this, except Firefoxalert ("yo!");}
} var Sayhi;//But if you define SAYHI variables first, when a function is used as a variable, then Sayhi is a function expression if (condition) {
sayhi = function () {alert ("hi!");};
} else {
sayhi = function () {alert ("yo!");};
}
Declaring a function execution context anonymous function