What is Lexical Scope in JavaScript?

Abdul Hay
2 min readJun 28, 2020

If you want to know the lexical scope of JavaScript, you need to know about the scope first.
Two types of Scope (Layer Special) are used to run JavaScript code or programs such as Global Scope and Functional/Local Scope. When executing JavaScript engine code or programs, look for variables from Local Scope to Local Scope or from Local Scope to Global Scope.

That is, the layer or layer to execute the code or program of the JavaScript engine is called the scope.

Lexical Scope is the scope to execute the program by creating access between the component’s current state (Layer / Scope) and Nested Scope and Global Scope respectively.

A closer look at the following example will give you a better idea of ​​the Lexical Scope..

Global Scope: Earth has only one function variable (function name).
Earth Scope: It contains variables a, b and tree. And has access to its global scope. It has declared variables a, b and tree in the Earth’s field. And it also has Global Scope access.

tree Scope: It has c variable and also has access to Global and Earth Scope.

That is, when the Earth (3) argument is passed in the Global Scope, the value of the b variable of the Earth Scope is determined and the c variable of the tree Scope determines the value of the tree() with the value of the variable b with the access of the Earth Scope.

And this process is Lexical Scope.



Abdul Hay

My real-world name is Abdul Hay and I’m from Bangladesh. At this moment I’m working as full-stack web developer at lovely company.