Facebook Pixel

What is shadowing in JavaScript?

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.

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.

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?

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
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.