In JavaScript, the execution context is the environment where code is executed. It contains all the information needed to run a piece of code, such as variables, functions, and the scope chain.
Execution context has two components:
Memory component
Code component
Memory component(memory allocation phase): The memory component is also called a variable environment. This is the place where all variables and functions are kept as key-value pairs.
Syntax : Key: value;
Example :
name: Shivaji
f() : { .... }
Code component(execution phase) :
A code component is also called a thread of execution.
A code component is a place where the whole JavaScript code is executed line by line, one after another.
Thread of execution is just like a thread in which the whole code is executed in one line at a time.
Actual values are assigned to variables after their execution.
Inside the code component, in every function call, there will be a new execution context(function execution context) will be created, and memory allocation and code execution can happen
An undefined value is assigned to all parameters and variables.
function code is copied.
After the execution function, the new execution context can be completely deleted.
After the execution of the whole program, the global execution context can be deleted.