Skip to solution
hardFrontend

What is the event loop?

473 views
01

Understand the problem

Question presented to candidate: "In your own words, what is the event loop, and why does JavaScript need one?"

What a strong answer should cover:

  • JavaScript runs on a single thread -- one call stack, one line of code executing at any given instant, no true parallelism inside that thread.
  • Slow operations (a timer, a network request, a file read) are NOT run on that thread inline -- they are handed off to the surrounding environment (the browser or Node.js runtime), which notifies JavaScript via a callback once the work is done.
  • The event loop is the mechanism that takes those finished callbacks and runs them on the call stack, but only once the stack is completely empty -- it never interrupts currently running code.
  • This is what "non-blocking" and "asynchronous" actually mean in JavaScript -- not literal multi-threading, but a single thread that never sits idle waiting on slow work.
  • The precise queue mechanics (microtasks vs macrotasks, exact draining rules) are a deeper layer on top of this big picture -- worth naming that a fuller answer exists if the interviewer wants to go deeper.

Clarifying questions expected:

  • "Would you like the big-picture explanation, or should I go straight into the microtask/macrotask queue mechanics?"

Code / implementation expected: Optional -- a short snippet showing that code after a setTimeout call still runs before the timer fires is enough to illustrate the concept.

event loopconcurrencysingle-threadasync
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 who need a clear, concise definition of the event loop for a definitional interview question. Difficulty: Easy

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

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSScript continues past an async call instead of waiting on it (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 147 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track