DEV Community

Mahin Tazuar
Mahin Tazuar

Posted on

Javascript Exicution Context

When a JavaScript engine executes a script, it creates execution contexts. Each execution context has two phases: the creation phase and the execution phase.
The creation phase

When a script executes for the first time, the JavaScript engine creates a Global Execution Context. During this creation phase, it performs the following tasks:

Create a global object i.e., window in the web browser or global in Node.js.
Create a this object binding which points to the global object above.
Setup a memory heap for storing variables and function references.
Store the function declarations in the memory heap and variables within the global execution context with the initial values as undefined.
In our example, during the creation phase, the JavaScript engine stores the variables x and y and the function declaration timesTen() in the Global Execution Context. Besides, it initializes the variables x and y to undefined.

The execution phase
During the execution phase, the JavaScript engine executes the code line by line. In this phase, it assigns values to variables and executes the function calls.

ref:https://www.javascripttutorial.net/javascript-execution-context/

Top comments (0)