DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • Scope & Closures
  • Asynchronous JavaScript
  • DOM Manipulation
  • ES6+ to 2026
  • Execution Context & Call Stack
  • Hoisting: var, let, const & Functions
  • Data Types & Type Coercion
  • Prototypes & the this Keyword
  • The Event Loop Deep Dive
  • Higher-Order Functions, Currying & Functional Patterns
  • Callbacks, Promises & Async/Await
  • Event Delegation & DOM Optimization
  • Destructuring, Spread/Rest & Modern Syntax
  • ES Modules & the Fetch API
  • Memory Management & Garbage Collection
  • Debouncing, Throttling & Performance Patterns
  • Design Patterns in JavaScript
  • Proxies, Reflect & Symbols
  • JavaScript Optimizations & Best Practices
  • JavaScript Interview Questions (30 MCQs)
← From Beginner to Expert in Fundamentals of Frontend

Execution Context & Call Stack

20 min read
Execution ContextCall StackLIFOCreation PhaseStack OverflowDevTools Debugging

How JavaScript Tracks What's Running

Every time JavaScript runs code, it creates an Execution Context — a wrapper around the currently executing code that tracks variables, the scope chain, and the value of this.

Types of Execution Contexts

TypeCreated WhenContains
Global ECScript loadsGlobal variables, window/globalThis
Function ECFunction is calledLocal variables, arguments, this
Eval ECeval() runsDynamic scope (avoid!)

The Call Stack (LIFO)

The Call Stack is a data structure that records where in the program we are. When a function is called, it's pushed onto the stack. When it returns, it's popped off.

function third() { console.log("3rd"); }
function second() { third(); console.log("2nd"); }
function first() { second(); console.log("1st"); }
first();
// Call Stack: [global] → [first] → [second] → [third]
// Output: 3rd, 2nd, 1st

Stack Overflow

If the call stack exceeds its limit (typically ~10,000–15,000 frames), you get a RangeError: Maximum call stack size exceeded.

// ❌ Infinite recursion = stack overflow
function infinite() { infinite(); }
infinite(); // RangeError!

Creation Phase vs Execution Phase

Each execution context goes through two phases:

  1. Creation Phase: Memory allocated for variables (undefined for var, uninitialized for let/const), functions hoisted entirely.
  2. Execution Phase: Code runs line-by-line, variables get assigned.
console.log(a); // undefined (var is hoisted)
console.log(b); // ReferenceError (TDZ for let)
var a = 10;
let b = 20;

Visualizing with Chrome DevTools

Open DevTools → Sources → Set breakpoints → Watch the Call Stack panel on the right. This shows exactly which functions are stacked.

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.