Guides/Event Loop Interview Questions

Event Loop Interview Questions

Answers interviewers actually look for — plus snippets to rehearse in the visualizer.

Rajan Pandey · About the author

Rajan Pandey is a Full Stack AI Engineer with nearly 3 years of professional experience building production-ready web applications, SaaS platforms, and developer-focused tools. He specializes in JavaScript, TypeScript, React.js, Next.js, Node.js, and the MERN stack.He has worked on 15+ production applications across SaaS, EdTech, and GenAI products, with experience spanning frontend architecture, backend development, REST APIs, database design, authentication, and third-party integrations. StackTools was created as a way to make everyday development tasks simpler and JavaScript concepts easier to understand through interactive, browser- based tools.His goal is to build practical utilities that developers can use without unnecessary complexity, registration, or uploading their data to external servers.

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 t
Open in Visualizer

What 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 4
Open in Visualizer

Practice 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”.

Try it live

Open the matching StackTools utility — runs in your browser.

Open JS Execution Visualizer