Execution context have two components:
Variable Environment or Memory Component – Stores Key value pairs
Thread of Execution or Code Component – Code gets executed one line at a time.
Three types of execution context:
Global Execution Context
Functional Execution Context
Eval Function Execution Context
A new execution context gets created every time a function is executed, as the engine parses through your code.
When a new execution context is created on a function call, first step memory creation phase.
After memory creation phase, step by step execution of code takes place.
So how does it manages all this?
Whenever the engine finds a function invocation, it creates a new execution context for that function and pushes it to the top of the stack.
The engine executes the function whose execution context is at the top of the stack.
When this function completes, its execution stack is popped off from the stack, and the control reaches to the context below it in the current stack.
Please check below the video for detailed explaination along with line by line code execution demo: