Event Loop

hard

Complete guide with examples and interview questions · 45 min

Definition

Say it out loud in an interview — clear, simple, no textbook wording.

JavaScript runs on a single thread with one call stack. It cannot run two functions at the same time in that thread. Yet we use timers, network requests, and Promises without blocking the UI.

The event loop is the coordinator: when the stack is empty, it pulls work from queues and pushes callbacks back onto the stack. Understanding this model is non-negotiable for senior JavaScript interviews — especially output-prediction questions.

Quick Stats
45
Minutes
hard
Difficulty
5
Interview Q's

Key takeaways

  • JavaScript is single-threaded — one call stack, one thing at a time
  • The event loop decides when queued callbacks run after the stack clears
  • Microtasks (Promises) always run before the next macrotask (setTimeout, I/O)
  • `setTimeout(fn, 0)` is not instant — it waits for the stack and microtasks
  • Browser and Node event loops differ (Node has libuv phases)

Track your mastery

Sign in to save Q&A scores, coding challenge progress, points, and streaks across devices.

Sign in to save progress