Q5: What is Scope and the Scope Chain?
Scope determines the accessibility of variables in code. JavaScript has Global Scope, Function Scope, and Block Scope. When a variable is referenced, JavaScript looks in the current scope; if not found, it traverses up the Scope Chain to outer enclosing scopes until it reaches the global scope.
Key Takeaways
Lexical scope means inner scopes can access outer scope variables.
The scope chain lookup travels outward up to global scope.
Knowledge Check
Where does lexical scope determine variable accessibility from?