- JavaScript
- The Event Loop, Microtasks, and Asynchronous Concurrency
JavaScript Async Interview Questions: Event Loop
JavaScript async interview questions cover the single most tested topic in modern FAANG frontend interviews: asynchronous execution. Interviewers frequently present interleaved code combining `setTimeout`, `Promise.resolve`, `queueMicrotask`, and async functions to evaluate whether you truly grasp the browser runtime event loop.
Our interactive lessons step through the exact microtask queue draining cycle that happens before the next macrotask or browser rendering tick. Learn how to write resilient Promise chains, handle edge cases with Promise combinators, and build production-grade concurrency throttles.
JavaScript Async Interview Questions: 8 lessons
1. Event Loop & Microtasks
Interactive ReadyThe event loop in JavaScript is a runtime concurrency mechanism that coordinates single-threaded code execution across the Call Stack, Microtask Queue, and Task Queue. Synchronous code executes first, followed by the complete draining of all microtasks (Promises, queueMicrotask) before the next macrotask (setTimeout, I/O) is processed.
2. Promises & Chaining
Interactive ReadyPromises in JavaScript represent the eventual completion or failure of an asynchronous operation; each one exists in one of three states: pending, fulfilled, or rejected, and promise chaining builds on that. Chaining works because every .then() and .catch() returns a new Promise, with unhandled errors propagating downstream until caught.
3. async/await Internals
Interactive Readyasync/await is syntactic sugar over Promises and Generators that allows writing asynchronous code with synchronous control flow. An async function executes synchronously until its first await expression, which pauses function execution, yields control to the caller, and schedules resumption as a microtask.
4. Promise Combinators
Interactive ReadyPromise combinators coordinate collections of concurrent promises: Promise.all requires all to fulfill and fails fast on the first rejection; Promise.allSettled waits for all outcomes; Promise.race settles with the first settled promise; and Promise.any fulfills with the first resolved promise.
5. Timers & Concurrency Control
Interactive ReadysetTimeout in JavaScript and setInterval differ in one way: both schedule callbacks in the macrotask queue to execute after a minimum delay once the call stack is clear, but setTimeout runs once and setInterval repeats. Recursive setTimeout is preferred over setInterval to avoid execution drift and callback bunching, while requestAnimationFrame is ideal for 60fps UI animations.
6. Promise Concurrency Pool
Interactive ReadyA Promise Concurrency Pool restricts active in-flight promises to a maximum concurrency limit K, using an internal active task set and Promise.race to drain slots as tasks finish while preserving original input order.
7. Async Iterators & Streaming Backpressure
Interactive ReadyAsync iterators implement Symbol.asyncIterator returning promises for { value, done }, consumed via for await...of. They provide pull-based streaming with automatic backpressure and deterministic finally block cleanup on early loop termination.
8. Node.js Event Loop
Interactive ReadyThe Node.js event loop is libuv's loop that runs callbacks in phases: timers, pending callbacks, poll (I/O), check (setImmediate) and close callbacks. After the current callback, Node drains the process.nextTick queue and then the promise microtask queue before moving on, so nextTick runs before promises, and inside an I/O callback setImmediate always runs before a 0 ms setTimeout.
