Lexically (statically) scoped. The scope chain is determined by where functions are written in the source, not where they are called. Dynamic calls do not change the chain.
Nested Functions and Scope Resolution in JavaScript
Is JavaScript lexically or dynamically scoped?
The answer
More FAQs in Nested Functions and Scope Resolution in JavaScript
Through the scope chain. The engine looks in the current variable environment, then follows the outer environment reference up to the lexical parent, repeating until the variable is found or the global scope is reached.
When a local variable has the same name as a variable in an outer scope. Inside the inner scope, the local variable is used and the outer one is hidden. The outer is not affected.
No. Because JavaScript is lexically scoped, the scope chain is fixed at write time. Calling a function from a different location does not give it access to that location's variables.
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.