Execution Context in JavaScript

In JavaScript, execution context refers to the environment in which the JavaScript code is evaluated and executed. It is the context or the "scope" within which code runs and determines how variables, functions, and objects are accessible.

https://www.youtube.com/watch?v=zdGfo6I1yrA

Key Points:

  1. Global Execution Context: This is the default or outermost context where any JavaScript code starts executing. When the script is run, a global execution context is created.
  2. Function Execution Context: Each time a function is called, a new execution context is created for that function. It is isolated from other contexts and contains the variables and functions specific to that function.
  3. Eval Execution Context: This is the context created when using the eval() function (though rarely used and not recommended).

Phases of Execution Context

Each execution context goes through two phases:

  1. Creation Phase:
  2. Execution Phase:

Components of Execution Context

An execution context contains the following components:

  1. Variable Object (VO):
  2. Scope Chain:
  3. this Value:

Execution Context Stack (Call Stack)