Does calling a function from a different scope change its variable resolution?
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.
Verify This Answer
Cross-check this information using these trusted sources:
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.
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.
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.
Still have questions?
Browse all our FAQs or reach out to our support team
