JS scope and execution Environment:
1. Scope Chain:
<1> use: Ensures an orderly access to all variables and functions that the execution environment has access to.
<2> Composition:
A. The front end of a scope chain is always a variable object in the context of the current execution code (if the environment is a function, its active object is used as a variable object, and the active object initially contains only one variable, the arguments object);
B. The next variable object comes from the containing (external) environment;
C The last object, the variable object for the global execution environment.
<3> identifier parsing: is the process of searching for identifiers one level along the scope chain, always starting at the front end of the scope chain, and then backtracking backwards until the identifier is found.
2. Extend the scope chain:
Catch block for <1>try-catch statement: Creates a new variable object that contains the declaration of the thrown Error object;
<2>with statement: The specified object is added to the scope chain;
3. There is no block-level scope in JS:
<1> the variable declaration in the IF statement adds the variable to the current execution environment;
<2> variables declared with Var are automatically added to the closest environment
JS Scope chain