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.

HardTechnical
65 practiced
Implement a simplified Promise from first principles in JavaScript named `SimplePromise`. The implementation must support: creating with `new SimplePromise((resolve, reject) => {})`, `.then(onFulfilled, onRejected)` chaining, proper state transitions (pending -> fulfilled/rejected), asynchronous invocation of handlers (via queueMicrotask or equivalent), and basic thenable assimilation. It does not need to implement every edge of the full spec, but should handle chained Thens and errors correctly.
HardSystem Design
86 practiced
Design a deterministic test harness to assert microtask and macrotask ordering across browsers (Chrome, Firefox, Safari) and Node. Specify the sequence of operations (logs) you'd schedule using Promise.resolve, queueMicrotask, MutationObserver, setTimeout, and requestAnimationFrame to capture ordering and how you'd automate runs (e.g., Puppeteer, Playwright). Provide example assertions and methods to reduce flakiness due to timing variability.
MediumTechnical
83 practiced
Given the snippet below, predict the console output and explain why each line appears in that order. Focus on how microtasks, macrotasks and additional setTimeout calls are scheduled.
js
console.log('A');
setTimeout(() => console.log('B'), 0);
Promise.resolve().then(() => console.log('C'));
Promise.resolve().then(() => { console.log('D'); setTimeout(() => console.log('E'), 0); });
console.log('F');
EasyTechnical
76 practiced
You're implementing a gallery. Explain the difference between Promise.all and Promise.race and give two concrete usage scenarios on the frontend: one where Promise.all is appropriate and another where Promise.race is better. Discuss how each handles fulfillment and rejection and the UX implications.
EasyTechnical
61 practiced
Explain the differences between callback-based asynchronous code, Promises, and async/await in JavaScript. Describe how error handling behaves in each approach and provide short JavaScript examples that show equivalent behavior for: (1) a callback-style function, (2) a Promise-based function, and (3) the same flow using async/await. Mention common pitfalls for each approach (e.g., callback nesting, unhandled rejections, forgetting try/catch).

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.