Scope Chain and Hoisting
Learn Scope Chain and Hoisting (Phase 4 · Scope, Hoisting, Closures, this (Essential), JavaScript) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Where a variable is visible • Global scope : visible everywhere. Function scope : visible inside the function. Block scope ( let / const ): visible inside the { } block. • When a name is used, JavaScript looks in the current scope, then the enclosing scope, and so on outward to global: the scope chain . Inner scopes can read outer variables, never the reverse. • An inner variable with the same name shadows the outer one.