Through the outer environment reference in its execution context. This forms the scope chain. If a variable is not found locally, the engine walks up the chain to the lexical parent.
Function Execution Context and Local Scope
How does an inner function access outer variables?
The answer
More FAQs in Function Execution Context and Local Scope
Its execution context. Parameters, var declarations (function-scoped), let/const (block-scoped), and inner function declarations form the local scope. Each call gets its own.
No. Each recursive call creates its own execution context and local scope. Each call has its own copy of parameters and local variables, which is why recursion works correctly.
Yes, if it returns an inner function that captures the local scope. This is a closure. The variable environment stays alive as long as the inner function exists.
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.