Additional Notes - Execution Context and Execution Stack-2686
Additional Notes - Execution Context and Execution Stack-2686
Execution Context
● An Execution context is an environment where JavaScript code is executed.
● The Global Execution Context is the default execution Context where all
javascript code that is not inside of any function.
● Everything happens in a global execution context.in this phase, memory is
allocated to all the variables and functions.
● There can be only one global execution context in a program.
Execution Stack:
● An execution stack is used to store all the execution contexts which are
created during the code execution.
● An execution stack is also known as a calling stack(LIFO structure) in other
programming languages.
● When the JavaScript engine first encounters JavaScript code, it creates a
global execution context at the bottom and all the subsequent function
invocation is pushed to the top of the stack.
● The JavaScript 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.
E.g. What happens when you invoke a function: