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
In a large frontend codebase you see intermittent 'Unhandled Promise Rejection' warnings. Propose a systematic architecture and team-level patterns to reduce unhandled rejections and improve error observability. Include code examples: a centralized request wrapper that always handles errors, global handlers for unexpected rejections, and how to enforce these patterns during code review and testing.
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.
MediumTechnical
58 practiced
Implement a polyfill for Promise.allSettled named `allSettled(promises)` that accepts an iterable of Promises or values and returns a Promise that resolves to an array of result objects of the form `{status: 'fulfilled', value}` or `{status: 'rejected', reason}` in the input order. The implementation should work in environments that lack Promise.allSettled.
HardTechnical
82 practiced
Implement a TokenBucket rate limiter in JavaScript with the following characteristics: a maximum capacity (burst), refill rate (tokens per second), and methods `tryRemove(count)` which returns true/false immediately and `remove(count)` which returns a Promise that resolves when tokens become available. Ensure the implementation scales to many concurrent callers efficiently without creating many timers.
EasyTechnical
58 practiced
Implement a debounce utility in JavaScript:
`function debounce(fn, wait, immediate = false)`
It should return a debounced function that delays invoking `fn` until after `wait` milliseconds have elapsed since the last call. If `immediate` is true, `fn` is invoked on the leading edge. The implementation should preserve `this` and passed arguments and support canceling a pending call via a `cancel` method on the returned function.

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.