JavaScriptEasy
Explain the concept of lexical scoping
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
Lexical scoping means that the scope of a variable is determined by its location within the source code, and nested functions have access to variables declared in their outer scope. For example:
js
function outerFunction() {
let outerVariable = "I am outside!";
function innerFunction() {
console.log(outerVariable); // 'I am outside!'
}
innerFunction();
}
outerFunction();
In this example, innerFunction can access outerVariable because of lexical scoping.
