- Syntax Parser
- Execution Contexts
- Lexical Environment
It is simply a program that reads your code and decides what it does and whether the code you wrote is grammatically correct.
When you write a line of code, the computer, seeing all the functions and loops, does not quite know what to do.
Fortunately, there are programs responsible for the "translation" of what has been written by us into a language that the computer will understand. Such programs are called compilers.
Our code is read character by character and checked if the syntax and the code are correct. After that compiler does its job and compiles what has been written in a way that the computer can understand.
You can think about your code in the following way:
- You have your code.
- There is a program that converts what you wrote into a set of instructions that will be understood by the computer
Lexical Environment exists in languages in which it matters where the code is written.
When it comes to Lexical Environment, for example, of a function or a variable, we are really talking about where they will be located in the computer's memory after compilation. How they will interact with other functions, variables or elements of the program.
Simply "Where is it written and what surrounds it".
For example in the example above, the function first and second sit both lexically in the same place. Same goes for variable a and variable b. On the other hand in function second, variable c and d do not belong to the same lexical environment as variable e because it was created inside function third.
Execution context is an abstract concept used by the ECMAScript specification. Everytime a script is run a Global Execution Context is created, also everytime a function is run a Execution Context of that function is created too. As you can see in the above example we can find a lot of Lexical Environments in a simple script, however, which one is currently running is defined by the Execution Context. I will talk a lot about it in later parts of this blog.