Skip to solution
hardFrontend

Explain the event loop, call stack, and task queues.

1.2k views
01

Understand the problem

Question presented to candidate: "Walk me through what the call stack, the event loop, and the task queues actually are, and how they work together when JavaScript runs asynchronous code."

What a strong answer should cover:

  • The call stack is a real, finite, last-in-first-out (LIFO) structure of function frames -- the innermost call always finishes before the call that made it resumes.
  • JavaScript is single-threaded: only one frame executes at a time, so a long-running synchronous function blocks everything else, including timers and promise callbacks.
  • The event loop is the mechanism that, once the call stack is completely empty, checks the microtask queue (fully drains it), then runs exactly one macrotask, then repeats.
  • Two separate queues exist for queued async work: the microtask queue (Promise reactions, queueMicrotask) and the macrotask/task queue (setTimeout, setInterval, I/O, UI events).
  • A callback in either queue can only start running once the call stack is empty -- queued work never interrupts currently running synchronous code.

Clarifying questions expected:

  • "Do you want the browser event loop specifically, or should I also mention how Node.js differs (for example process.nextTick)?"

Code / implementation expected: Yes -- a short, runnable snippet demonstrating that a synchronous busy loop delays both a queued timer and a queued microtask.

event-loop
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript event loop and async-mechanics interview questions. Difficulty: Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every result below was actually run on Node.js v24.19.0 — the

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSCall stack LIFO order, then a busy loop delaying a queued timer and microtask (run directly)
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 119 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track