Scope & the Scope Chain
Every variable lookup walks outward until it finds a match — or runs out of places to look.
Scope decides where a variable is visible. Global scope is visible everywhere. Function scope is visible inside that function. Block scope (from `let`/`const`) is visible only inside the nearest `{ }`. When JavaScript needs a variable's value, it doesn't just look in the current scope — it walks outward through each enclosing scope, in order, until it finds the name or runs out of scopes. That ordered path outward is the scope chain, and it's fixed at the moment the code is written (lexical scope), not at the moment it runs.
inner() has no local variable of its own, so each lookup climbs the scope chain — first checking inner, then outer, then global — stopping as soon as a match is found.