Facebook Pixel

What is the scope chain in JavaScript?

The linked list of lexical environments that the engine walks to resolve a variable. It looks in the current environment first, then follows outer references up to the global scope. If not found, it throws ReferenceError.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in The Scope Chain in JavaScript: How Variable Resolution Works

At definition time. The outer references are determined by where functions are written (lexical scope), not where they are called. This is why a function called from a different scope does not gain access to that scope's variables.

A local variable with the same name as an outer one shadows the outer. The engine finds the local first and stops searching, so the outer variable is hidden but not affected.

A closure keeps its scope chain (outer references) even after the outer function returns. This lets the inner function access the outer function's variables later. The chain persists because the lexical environment is retained.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0