InterviewStack.io LogoInterviewStack.io

Asynchronous JavaScript and Event Loop Questions

Comprehensive understanding of asynchronous programming in JavaScript including callback functions and the pitfalls of callback nesting, Promises including their lifecycle and state transitions, promise chaining, and common utility methods such as Promise.all, Promise.race, and Promise.allSettled. Knowledge of async and await as syntactic sugar over Promises, proper error handling patterns using try catch and promise catch, and avoiding unhandled rejections. Practical skills for working with multiple concurrent operations such as coordinating parallel requests, implementing retry logic, rate limiting, throttling and debouncing of async calls, and handling race conditions. Deep understanding of the JavaScript event loop model including the call stack, task queue, microtask queue, the ordering of macrotasks versus microtasks, how timers and promise callbacks are scheduled, and how this affects concurrency and ordering. Familiarity with implementing a simplified Promise from first principles to demonstrate internal behavior, diagnosing timing and ordering bugs, and designing solutions for real world asynchronous flows and performance considerations.

MediumTechnical
64 practiced
Write a `retryFetch(url, options, retries, backoffBaseMs)` function in JavaScript that attempts to fetch a resource and retries on transient failures (network errors and 5xx responses) with exponential backoff and jitter. Use AbortController to time out individual attempts. Stop retrying on non-retriable status codes (4xx) and reject the returned Promise with a descriptive error.
EasyTechnical
79 practiced
Explain the microtask queue and macrotask (task) queue differences. List APIs that schedule microtasks (e.g., Promise.then, queueMicrotask, MutationObserver) and macrotasks (e.g., setTimeout, setInterval, I/O callbacks). Explain the practical consequences for UI responsiveness and ordering in a browser.
MediumTechnical
66 practiced
Implement `runWithConcurrency(tasks, concurrency)` in JavaScript. `tasks` is an array of functions that each return a Promise. The function should run at most `concurrency` tasks in parallel and resolve to an array of results in the original order. Optionally support a mode to either fail-fast (reject on first error) or gather all results (like allSettled).
HardSystem Design
58 practiced
You must load 50 independent widgets on a dashboard, each requiring a separate API call. Compare four strategies: (A) Promise.all (full parallel), (B) sequential fetch, (C) limited concurrency pool, and (D) streaming/prioritized incremental rendering as responses arrive. For each, analyze latency, CPU/memory footprint, network utilization, UX trade-offs, error handling and caching. Provide concrete code patterns for approaches (C) and (D) and recommend when to pick each approach.
MediumTechnical
65 practiced
Design `cancelableFetch(url, options, timeoutMs)` that returns an object `{ promise, cancel }`. `promise` behaves like `fetch` but rejects if canceled or timed out; `cancel()` aborts the in-flight request via AbortController. Implement the wrapper and explain edge cases like multiple cancels, cleaning timers, and ensuring the promise settles exactly once.

Unlock Full Question Bank

Get access to hundreds of Asynchronous JavaScript and Event Loop interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.