The difference between scope and execution context
A difference:
- The global execution context is created immediately before the JS code executes after the global scope is determined [1].
- The function execution context is when a function is called (
fn()
), created before the function body code is executed.
Difference between 2:
- In addition to the global scope, each function creates its own function scope,
The scope is defined when the function is defined
, rather than when the function is called- The scope is static, existing as long as the function is defined and does not change.
- The execution context is dynamic, and when a function is called (
fn()
), automatically released after the call ends
contact
- The context (object) is subordinate to its scope.
- The global context (object) corresponds to the global scope.
- The function context (object) corresponds to the function scope.
Execute the context life cycle
- Creation Phase [1]
- Generating variable objects
- Create the arguments
- Scanning function declaration
- Scanning variable declaration
- Create the arguments
- Simultaneous scope chains
- Make sure this points to
- Generating variable objects
- Execution phase
- Variable assignment
- Function reference
- Execute other code