Scope
A scope defines the region where variable names and bindings are visible, in two kinds: lexical (static) and dynamic.
Purpose
Control variable visibility and lifetime, preventing naming conflicts.
Mechanism
Lexical scope: determined by code structure (fixed at compile time). Dynamic scope: determined by the call chain (resolved at runtime). Block scope (let/const) vs function scope (var). Closures capture the lexical scope.
Use cases
- Variable management
- Understanding closures
- Name isolation