Explain the event loop in one minute
JavaScript runs on a call stack. Async APIs schedule callbacks onto queues. When the stack is empty, the host runs microtasks to completion, then takes the next macrotask (timer, I/O, etc.). Repeat. That loop is how a single thread interleaves sync work and deferred callbacks.
Why does Promise beat setTimeout(0)?
Promise reactions are microtasks; setTimeout callbacks are macrotasks. After sync code, the microtask queue drains before any timer — even with delay 0.
setTimeout(() => console.log("t"), 0);
Promise.resolve().then(() => console.log("p"));
// p then tOpen in VisualizerWhat does async/await compile to?
Roughly: an async function returns a Promise; await splits the function into Promise continuations. Resumption uses the same microtask machinery as .then.
Can microtasks starve rendering?
Yes in browsers. Continuously scheduling new microtasks delays the next rendering opportunity. Prefer yielding with setTimeout, scheduler APIs, or chunking work.
Predict this output
console.log(1);
setTimeout(() => console.log(2), 0);
Promise.resolve().then(() => {
console.log(3);
setTimeout(() => console.log(4), 0);
});
console.log(5);
// 1 5 3 2 4Open in VisualizerPractice set
Work through the 10 output puzzles and the event loop guide. Narrate queues out loud — interviewers care about the explanation more than memorized answers.
When interview answers are enough
Knowing queue priority gets you through whiteboard rounds. Shipping performance still needs profiling, React concurrent features, and Worker offload — topics beyond “Promise vs setTimeout”.