Through the scope chain. Each execution context has an outer environment reference pointing to its lexical parent's environment. The engine walks this chain to resolve variables not found locally.
How Functions Work in JavaScript Under the Hood
How does an inner function access outer variables in JavaScript?
The answer
More FAQs in How Functions Work in JavaScript Under the Hood
A new function execution context is created, the memory phase allocates locals (var as undefined, functions in full), a frame is pushed on the call stack, the body runs line-by-line, and the frame is popped on return.
The part of an execution context that holds local variables, function arguments, and inner function declarations. Each function call has its own variable environment, so recursion and re-entrancy are safe.
No. Each recursive call creates a new execution context with its own variable environment. Each call has its own copy of local variables, which is why recursion works correctly.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.