JavaScript parsing order and variable scope
The scope of a variable
1. Global variables: The resulting variable can be accessed anywhere in the code, with a global scope.
A. Variables defined outside the outermost function.
B. There are no variables that define a direct assignment, and have global properties.
2. Local variables: can only be accessed in a fixed code fragment (in a function fragment).
A. A variable that is defined inside a function is a local variable.
B. The parameter is also a local variable.
Second, JavaScript pre-parse order
1, <Script></script> block in turn to parse;
2, parsing the environment of code operation;
3, the identifier (keyword) (var function) to parse, resolved to the corresponding environment;
4, if there are <Script></script> block and then follow the above steps to parse.
Third, the noun explanation
(1) Environment:
1. Hosting environment
2. Execution Environment
The execution environment determines the access rights of variables and functions.
A. Global Environment
B. Function environment
C.eval ();
(2) Scope
The scope of a piece of code.
(3) Scope chain
Variables and functions that have access in an execution environment can be accessed in an orderly and organic manner.
JavaScript parsing order and variable scope