Facebook Pixel

How do closures relate to nested functions and scope?

A closure is an inner function that keeps its outer environment reference even after the outer function has returned. The scope chain persists, so the inner function can still access the outer 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

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.