Tech
Lexical Scope
What is Lexical Scope?
Lexical scope is the rule that determines where a variable can be accessed based on where the code is written .
The word lexical basically means that JavaScript determines the scope by looking at the structure of the code. It does not matter where a function is called from; what matters is where that function was defined .
For example:
let name = " John " ;
function greet () {
console . log ( name );
}
greet ();
...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to