What does 'lexical' mean in JavaScript scoping?
It means the outer environment reference is determined by where the code is written in the source, not where the function is called. This is why JavaScript is called lexically (statically) scoped.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Lexical Environment in JavaScript Explained
An internal data structure that manages scope. It consists of an environment record (the variable bindings) and a reference to the outer (parent) lexical environment. The engine creates one for each scope.
In the spec, the variable environment holds var and function declarations, while the lexical environment holds let and const. In practice they are often the same object, but the distinction matters in edge cases like catch blocks.
When a function is returned or passed around, it keeps a reference to its lexical environment. That reference lets it access variables in its lexical chain even after the outer function has returned. This is what a closure is.
Still have questions?
Browse all our FAQs or reach out to our support team
