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.