5.1 Scope & the Scope Chain
Scope establishes the accessibility and lifetime of variables in code. JavaScript enforces lexical scoping (static scoping): the scope of an identifier is established by its author-time source code block nesting.
Figure 5.1: Scope lookup moves strictly outward from innermost scope to outer scopes until it reaches the global object, never inward.
5.2 Execution Context
An Execution Context is the internal runtime environment created by the JavaScript engine whenever code runs. It contains local variables, the scope chain, and the this binding for that specific execution frame.
Figure 5.2: Every execution context undergoes a Creation Phase (memory allocation & hoisting) followed by an Execution Phase (evaluation & assignment).
5.3 The Temporal Dead Zone
The Temporal Dead Zone (TDZ) is the specific temporal interval between the start of a scope and the line where a let or const variable declaration is evaluated in memory.
Figure 5.3: Accessing a variable while in the TDZ throws a ReferenceError, preventing undefined bugs.