A function is a special object;
Object: A collection of properties (name-value pairs);
The function is used to initialize (with the new operator) a newly created object is called a constructor.
The object is called as a method when the property is a function.
Within a function body, a local variable takes precedence over a global variable of the same name.
code example:
var scope = "global"; // Declare a global variable
functionCheckscope () {
varScope = "local";//life a local variable with the same name
returnScope//The value of the local variable is returned, not the value of the global variable
}
Checkscope ()//Local
Note that Var is not written before global variables, but must be written before local variables.
Declaration in advance (hositing) code example:
var scope = "global"; function f () {//should be Var Scope;var advance to thisConsole.log (scope); Output undefined, not "global"var scope = "local"; (scope = "local") var advance the variable in this assignment, but the variable itself is defined in the function body.Console.log (scope); Output "local"}
A scope chain is either an object list or a linked table. This set of objects defines the variables in the scope of this code. ( still not quite understand, to be solved )
JavaScript Definitive Guide, chapter 3rd several concepts