JavaScript Course
JavaScript
/
Advanced

Execution Context

Definition

An abstract concept representing the environment where JavaScript code is evaluated and executed. It contains the code, the 'this' binding, and the Lexical Environment (variables).

Explain Like I'm New

Imagine executing a JS file is like building a house. The Execution Context is the fenced-off construction site. It holds the blueprints (code), the workers (call stack), and the toolboxes (variables) needed to get the job done.

Real World Example

When a script runs, the engine creates the 'Global Execution Context'. Every time a function is called, a brand new 'Function Execution Context' is created and pushed onto the Call Stack.

Common Use Cases

  • •Understanding hoisting
  • •Debugging scope issues

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What are the two phases of an Execution Context?

intermediate

  • What is the difference between Global and Function Execution Context?

advanced

  • What is an Activation Object / Variable Environment?

Flash Cards

Question

What are the two phases?

Click to reveal answer
Answer

1. Creation Phase: The engine scans for variables/functions and allocates memory (Hoisting), and determines the value of `this`. 2. Execution Phase: The code is executed line by line and values are assigned to variables.