Async Operations
Promises, the event loop, timers, cancellation, concurrency limits and race conditions.
1.How do you handle errors in asynchronous operations?
try/catch with await, .catch, unhandled rejections, fetch HTTP errors, aggregation and retries.
2.How do you handle errors using try...catch blocks?
How try/catch works with sync and async code, and how to catch errors usefully.
3.How do you make an HTTP request using the Fetch API?
GET and POST with fetch, checking response.ok, timeouts and cancellation.
4.What are Promises and how do they work?
Promise objects, chaining, error propagation, microtask scheduling and Promise.withResolvers.
5.What is the use of `Promise.all()`
Running independent async work in parallel, fail-fast semantics and concurrency limits.
6.Contact Form
Build a contact form with accessible inline validation, a submitting state and a success message.
7.Digital Clock
Build a ticking digital clock that stays aligned to real seconds, with a 12/24-hour toggle and clean timer teardown.
8.Like Button
Build a toggle Like button that talks to a flaky API, with pending, error and accessible pressed states.
9.Cache Async (Deduplicate Requests)
Memoize an async function so concurrent calls share one in-flight promise, results expire after a TTL and failures are not cached.
10.Debounce
Delay invoking a function until a burst of calls has stopped for a given wait time.
11.Map Async
Map over a list with an async callback, running every call in parallel and keeping the results in input order.
12.Middlewares
Compose async middleware functions into one onion-style pipeline where each step can run code before and after next().
13.Promise.all
Implement Promise.all: resolve with every result in order, or reject on the first failure.
14.Promise.any
Implement Promise.any: fulfill with the first success, or reject with an AggregateError.
15.Promise Timeout
Wrap a promise so it rejects with a TimeoutError if it doesn't settle in time, without leaking timers.
16.Promisify
Convert a Node-style callback function into one that returns a promise.
17.Retry with Backoff
Retry a failing async operation with exponential backoff and a predicate that decides which errors are worth retrying.
18.Throttle
Limit a function to at most one call per wait window, with leading and trailing calls.
19.How do you abort a web request using `AbortController` in JavaScript?
Cancelling fetch with signals, timeouts, AbortSignal.any and cleaning up in effects.
20.What is async/await and how does it simplify asynchronous code?
Syntax over promises: sequential vs parallel awaits, error handling, top-level await and pitfalls.
21.How do you handle asynchronous data loading in React applications?
Server Components and loaders, query libraries, careful effects, Suspense and use().
22.What is the event loop? Explain the difference between the macrotask and microtask queues.
How JavaScript schedules callbacks, promises and rendering on a single thread.
23.How is `Promise.all()` different from `Promise.allSettled()`?
Fail-fast vs wait-for-everything, result shapes, and where any and race fit in.
24.Explain the different states of a Promise
Pending, fulfilled and rejected, what settled and resolved really mean, and why state is immutable.
25.What is React Suspense and what does it enable?
Declarative loading boundaries for lazy code, data, streaming SSR and selective hydration.
26.How can you test asynchronous code in JavaScript?
Awaiting promises, asserting rejections, fake timers and waiting for UI updates.
27.Autocomplete / Typeahead Component
Design a reusable, accessible autocomplete component with debounced search, caching, race handling and keyboard navigation.
28.Job Board
Build a paginated job board on a Hacker News-style API: fetch ids, then load job details in parallel pages.
29.Memory Game
Build a card-matching memory game with timed flip-back, move counting and screen-reader friendly announcements.
30.Progress Bars
Each click adds a progress bar that fills from 0 to 100% over two seconds, driven by requestAnimationFrame.
31.Stopwatch
Build an accurate stopwatch with start, stop, lap and reset, based on timestamps rather than counting ticks.
32.Toast Notifications
Build a toast system with a context API, live-region announcements, auto-dismiss that pauses on hover or focus, and a visible limit.
33.Traffic Light
Build a traffic light that cycles through configurable states with timers, a pause control and clean effect teardown.
34.Whack-a-Mole
Build a timed whack-a-mole game with random moles, scoring, a countdown and keyboard play, managing several timers safely.
35.Map Async with Limit
Map over a list with an async callback while never running more than a given number of calls at once.
36.Promise Implementation
Build a Promises/A+-style MyPromise with then, catch, finally, chaining and thenable adoption.
37.Promise Pool
Build a concurrency-limited task queue: tasks can be added at any time and at most N run at once.
38.Explain `useTransition` and `useDeferredValue` and when to use each
Marking updates as non-urgent so concurrent React keeps input responsive.
39.Cancellable Interval
Wrap setInterval so it returns a cancel function that stops future ticks.
40.Cancellable Timeout
Wrap setTimeout so it returns a cancel function instead of a timer id.
41.Promise.race
Implement Promise.race: settle the same way as the first input to settle.
42.Promise.withResolvers
Implement Promise.withResolvers to create a promise you can settle from outside its executor.
43.Sleep
Write a promise-based sleep(ms) and explain why it pauses an async function but not the thread.
44.Explain the concept of a callback function in asynchronous operations
Passing functions to be called later, error-first callbacks, callback hell and inversion of control.
45.What are the different ways to make an API call in JavaScript?
fetch, XHR, sendBeacon, WebSocket, SSE and data-fetching libraries, and when to use each.
46.What are the differences between `XMLHttpRequest` and `fetch()` in JavaScript and browsers?
Promise-based fetch versus event-based XHR: errors, cancellation, streaming, progress and cookies.
47.Promise.allSettled
Implement Promise.allSettled: wait for every input and report each outcome in order.
48.Promise.resolve
Implement Promise.resolve, including promise pass-through and thenable adoption.
49.Promisify II
Extend promisify with a custom-implementation symbol, like Node's util.promisify.custom.
50.Run Async Tasks in Series
Run a list of async functions one after another, passing each result to the next and stopping at the first failure.
51.setInterval with setTimeout
Re-implement setInterval and clearInterval using only chained setTimeout calls.
52.Explain the concept of error propagation in JavaScript
How errors unwind the call stack, flow through promise chains and reach global handlers.
53.requestAnimationFrame vs requestIdleCallback vs setTimeout: when does each run and what is each for?
Frame-aligned visual work, idle-time background work, deadlines, throttling in background tabs and alternatives.
54.What is the difference between `setTimeout()`, `setImmediate()`, and `process.nextTick()`?
Where each callback lands in the Node.js event loop, and the browser equivalents.
55.Analog Clock
Draw a ticking analog clock in SVG with correctly rotated hour, minute and second hands and an accessible name.
56.Grid Lights
Build a grid of toggle lights that, once all are lit, switch off one by one in reverse activation order.
57.Infinite Scroll Feed
Build a cursor-paginated feed that loads more posts as you scroll, with abort handling, retries and the ARIA feed pattern.
58.Progress Bars II: Concurrency Limit
Extend the progress bars so at most three fill at once while the rest wait in a queue.
59.Async Queue with Priority
Run async tasks with a concurrency limit, starting higher-priority tasks first and keeping FIFO order within a priority.
60.Debounce II
Debounce with leading, trailing and maxWait options, plus cancel and flush.
61.What are iterators and generators in JavaScript and what are they used for?
The iteration protocols, function*, lazy sequences, async iteration and iterator helpers.
62.What is React Fiber and how is it an improvement over the previous approach?
Incremental, interruptible reconciliation with priorities, the basis of concurrent React.
63.What are workers in JavaScript used for?
Dedicated, shared and service workers: off-main-thread work, messaging, transferables and limits.