CodeZettaInterview Hub

JavaScript · Execution Context · Fresh / Intern · Concept

What is an execution context in JavaScript, and what are its main components?

Short Interview Answer

An execution context is the environment where JavaScript code is evaluated and executed. It holds the Variable Environment, Lexical Environment, and the value of `this`.

Detailed Explanation

Every time a function runs (or the global script starts), the engine creates an execution context. It has three main parts: (1) Variable Environment — bindings for `var` declarations and function declarations; (2) Lexical Environment — bindings for `let`/`const`, function arguments, and the outer environment reference used for scope chain lookup; (3) `this` binding — determined by how the function was called. There is always a Global Execution Context, and each function call pushes a new Function Execution Context onto the call stack. Understanding this model explains hoisting, scope, and `this` behavior.

Interview Tip

Draw the call stack and show how entering/leaving a function creates/destroys contexts — interviewers love a visual.

Common Mistake

Confusing execution context with scope. Scope is about variable visibility; execution context is the runtime container that includes scope, `this`, and the environment record.

Did you know this answer?