Asynchronous and Event-Driven Programming Questions
Non-blocking execution models: callbacks, promises and futures, async/await, event loops, and event-driven and reactive architectures. Covers reasoning about ordering, back-pressure, and error propagation in asynchronous flows, including data-fetching patterns. Central to modern frontend, backend, and mobile runtimes.
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.
Implement an EventLoopSimulator class in JavaScript that models a single-threaded event loop with a call stack, microtask queue, and macrotask queue. Provide methods scheduleMicrotask(fn), scheduleMacrotask(fn), and runOneTick() which runs one macrotask and then drains all microtasks generated during that macrotask, returning a log of executed tasks. The simulator is for deterministic teaching and unit tests.
You're loading 100 small resources on page load (avatars, metadata). Describe frontend strategies to optimize perceived and actual performance: batching requests, request deduplication, caching strategies (HTTP and in-memory), concurrency limiting, lazy-loading, and streaming incremental rendering. Provide pseudocode or snippets showing how to batch and dedupe requests on the client.
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).
List and explain the lifecycle and state transitions of a JavaScript Promise: pending -> fulfilled (resolved) -> rejected. Show with examples how handlers attached before and after resolution behave and explain why Promise.then always executes callbacks asynchronously. Mention the role of thenables in resolution.
Unlock Full Question Bank
Get access to all 33 Asynchronous and Event-Driven Programming interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.