Asynchronous programming in JavaScript enables non-blocking execution, allowing long-running operations such as network requests, file reading, or timers to run in the background without freezing the main thread. Because JavaScript is single-threaded, concurrency is managed via the Event Loop, which orchestrates execution between the call stack, macrotask queue, and microtask queue (handling promises). Over time, JS concurrency evolved from nested callback functions (“callback hell”) to cleaner ES6 Promises and modern syntactic sugar like async/await. Mastering how microtasks execute ahead of macrotasks, how to handle asynchronous error boundaries, and how non-blocking APIs operate is essential for building scalable web applications and passing technical engineering interviews.
JavaScript Asynchronous Programming
1 min read
Correct Answer: b) Single-threaded, non-blocking, asynchronous, and concurrent via an event loop
Explanation:
JavaScript executes code on a single main thread but achieves concurrency and non-blocking I/O using web APIs and the event loop.
Correct Answer: a) The Call Stack
Explanation:
The call stack is a LIFO (Last In, First Out) data structure that records execution contexts.
Correct Answer: b) Into the Task Queue (or Macrotask Queue)
Explanation:
When asynchronous operations finish, their callbacks are queued in the Task Queue, waiting for the call stack to clear.
Correct Answer: b) Microtask Queue
Explanation:
The event loop checks and empties the entire Microtask Queue before moving on to any macrotask.
Correct Answer: c) Promise.prototype.then() / catch() / finally()
Explanation:
Settled promise callbacks and queueMicrotask() explicitly place callback jobs into the microtask queue.
Correct Answer: c) setTimeout()
Explanation:
setTimeout, setInterval, setImmediate, and I/O events are placed in the macrotask queue.
Correct Answer: b) Deeply nested callback functions resulting from multiple asynchronous operations depending on one another
Explanation:
Callback hell occurs when multiple asynchronous tasks are chained using nested callbacks, creating unmaintainable code.
Correct Answer: b) They eliminate callback hell by providing cleaner chaining (.then) and centralized error handling (.catch).
Explanation:
Promises provide a standardized abstraction for asynchronous results, enabling fluent chaining.
Correct Answer: a) Pending, Fulfilled, Rejected
Explanation:
A promise starts in 'pending', then settles into either 'fulfilled' or 'rejected'.
Correct Answer: b) No, a promise state is immutable once settled (fulfilled or rejected)
Explanation:
Once a promise is fulfilled or rejected, its state and value cannot change.
Correct Answer: a) A new Promise object that is already fulfilled with the given value
Explanation:
Promise.resolve() creates a promise resolved with the passed value.
Correct Answer: a) A rejected promise with the specified reason/error
Explanation:
Promise.reject returns a promise rejected with the provided reason object.
Correct Answer: a) It waits for all input promises to fulfill and returns an array of their fulfillment values. If any promise rejects, the entire returned promise rejects immediately.
Explanation:
Promise.all fails fast if any single promise in the iterable rejects.
Correct Answer: a) Promise.allSettled waits for all promises to settle and returns an array of status objects for each promise, never failing early.
Explanation:
Promise.allSettled gives the outcome of every promise regardless of failure.
Correct Answer: a) A promise that fulfills or rejects as soon as any one of the input promises settles
Explanation:
Promise.race settles as soon as the first promise in the iterable wins the race.
Correct Answer: a) It fulfills as soon as *any* of the input promises fulfills, ignoring rejections unless *all* input promises reject.
Explanation:
Promise.any looks for the first success; it only rejects with an AggregateError if every single input promise fails.
Correct Answer: a) It automatically makes the function return a Promise, allowing the use of `await` inside it.
Explanation:
An async function implicitly wraps its return value in a resolved promise.
Correct Answer: a) It pauses the execution of the async function until the awaited promise settles, resuming execution with the resolved value without blocking the main thread.
Explanation:
await suspends the execution of the async function context, returning control to the event loop.
Correct Answer: a) Using standard synchronous `try...catch` blocks
Explanation:
Rejected promises awaited inside an async function throw an exception that can be caught using standard try...catch.
Correct Answer: b) Schedules `fn` to run as soon as the call stack is empty and all microtasks have run, with a minimum browser-enforced delay.
Explanation:
A 0ms timeout pushes the callback to the macrotask queue after clearing the call stack and microtask queue.
Correct Answer: a) The ability to use the `await` keyword at the top level of an ES module without wrapping it in an async function
Explanation:
Modules can now use await at the top level, making modules act as large async functions.
Correct Answer: a) A generator function declared with `async function*` that yields promises and can be iterated using `for await...of`
Explanation:
Async generators yield promises and allow asynchronous iteration over streams of data.
Correct Answer: a) It iterates over async iterables or sync iterables, awaiting each yielded promise before proceeding to the next iteration.
Explanation:
for await...of pauses loop iteration until each awaited promise resolves.
Correct Answer: a) To abort ongoing asynchronous fetch requests or operations using an `AbortSignal`
Explanation:
AbortController provides a standard way to cancel ongoing fetch requests.
Correct Answer: a) An 'unhandledrejection' event fires on the global window or process, potentially logging an unhandled rejection warning.
Explanation:
Modern runtimes emit unhandledrejection events to alert developers about neglected promise rejections.
Correct Answer: a) Sequential execution awaits each task one after another, whereas parallel execution initiates all promises simultaneously and awaits them together via Promise.all.
Explanation:
Starting promises before awaiting runs them concurrently, reducing total execution time.
Correct Answer: a) A bug where the output depends on the non-deterministic timing or interleaving of unpredictable asynchronous operations
Explanation:
Race conditions occur when async operations finish in an unexpected order, corrupting state.
Correct Answer: a) Interval callbacks can queue up back-to-back or overlap without skipping delays depending on execution duration.
Explanation:
setInterval fires timers at fixed intervals regardless of whether the previous callback finished.
Correct Answer: a) It guarantees a fixed delay between the *end* of one execution and the *start* of the next, preventing overlapping pileups.
Explanation:
Recursive setTimeout schedules the next timeout only after the current callback completes.
Correct Answer: a) Queues a microtask safely to be executed before control returns to the event loop's macrotask queue
Explanation:
queueMicrotask is a clean API for executing custom code as a microtask.
Correct Answer: a) To execute cleanup code regardless of whether the promise was fulfilled or rejected
Explanation:
finally() runs when a promise settles, passing through the original resolution or rejection.
Correct Answer: a) A technique to delay function execution until a specified amount of time has elapsed since the last time it was invoked
Explanation:
Debouncing groups multiple rapid events into a single delayed execution.
Correct Answer: a) A technique ensuring a function is called at most once in a specified time period, no matter how many times triggered
Explanation:
Throttling guarantees regular execution intervals during continuous events.
Correct Answer: a) A script running in a background thread separate from the main execution thread, enabling true parallel computation in the browser
Explanation:
Web Workers allow running CPU-intensive JavaScript tasks in background threads.
Correct Answer: a) No, Web Workers do not have access to the window, document, or DOM.
Explanation:
Workers communicate with the main thread via message passing because they lack DOM access.
Correct Answer: a) Via asynchronous message passing using `postMessage()` and `onmessage` event handlers
Explanation:
Workers communicate by cloning or transferring data messages across thread boundaries.
Correct Answer: a) Attaching a single event listener to a parent element to handle events triggered on its descendants via bubbling
Explanation:
Event delegation optimizes memory and handles dynamically added elements efficiently.
Correct Answer: a) Caching the results of expensive asynchronous function calls based on input parameters to avoid redundant operations
Explanation:
Memoization saves resolved promise results for identical future inputs.
Correct Answer: a) Sync code -> Microtasks (Promises) -> Macrotasks (setTimeout)
Explanation:
The event loop clears synchronous call stack first, then all microtasks, and finally macrotasks.
Correct Answer: a) A strategy where failed network requests are retried with progressively longer delays to prevent server overload
Explanation:
Exponential backoff helps gracefully handle temporary network hiccups without flooding servers.
Correct Answer: a) A utility or pattern that limits the number of concurrently executing promises out of a large batch
Explanation:
Promise pools prevent overwhelming APIs or resources by throttling concurrent requests.
Correct Answer: a) To queue a callback to be executed before the browser performs the next repaint, ensuring smooth animations
Explanation:
rAF is optimized for visual animations, syncing execution with the display refresh cycle.
Correct Answer: a) setImmediate executes callbacks in the check phase, whereas setTimeout with 0ms executes in the timers phase.
Explanation:
In Node.js event loop phases, setImmediate and setTimeout(..., 0) handle phase separation.
Correct Answer: a) A synchronization primitive used to ensure that only one asynchronous operation accesses a critical shared resource at a time
Explanation:
Async mutexes prevent race conditions in single-threaded async code modifying shared state.
Correct Answer: a) A Promise that resolves to a Response object representing the response to the request
Explanation:
fetch returns a promise resolving to a Response object; it does not reject on HTTP error statuses.
Correct Answer: a) No, fetch only rejects on network failure; HTTP error statuses result in a fulfilled promise with `response.ok` set to false.
Explanation:
Developers must manually check `response.ok` or `response.status` to handle HTTP error codes.
Correct Answer: a) By calling `response.json()`, which returns a Promise resolving to the parsed JavaScript object
Explanation:
response.json() reads the response stream to completion and parses it as JSON asynchronously.
Correct Answer: a) It is the region where let/const variables are uninitialized before declaration; it affects async function bodies just like synchronous code.
Explanation:
TDZ scoping rules apply uniformly to all block scopes, including async function scopes.
Correct Answer: a) The value is automatically wrapped in a resolved promise and evaluated immediately.
Explanation:
Awaiting a non-promise value treats it as if it were `Promise.resolve(value)`.
Correct Answer: a) Combining multiple individual asynchronous requests into a single batched network payload to reduce HTTP overhead
Explanation:
Batching optimizes network performance by reducing round trips to servers.
Correct Answer: a) A situation where promises or their handlers retain memory references or leave handlers unattached, preventing garbage collection
Explanation:
Unresolved dangling promises or uncleared event listeners can cause memory retention.
Correct Answer: a) queueMicrotask() provides a clean, explicit semantic API specifically for queuing microtasks without needing to instantiate dummy Promise objects.
Explanation:
Both schedule microtasks, but queueMicrotask is designed explicitly for that purpose.
Correct Answer: a) Using `Promise.race()` combined with a `setTimeout` promise that rejects after X milliseconds
Explanation:
Racing a target promise against a rejecting timer promise is the standard pattern for promise timeouts.
Correct Answer: a) Loading asynchronous chunks of JavaScript code on-demand using dynamic `import()` only when needed
Explanation:
Dynamic import() returns a promise that resolves to the module, enabling efficient bundle code splitting.
Correct Answer: a) A Promise that resolves to the module namespace object of the requested module
Explanation:
Dynamic imports are asynchronous and return promises resolving to the imported module.
Correct Answer: a) It emits warnings or can terminate the process depending on configuration, hiding silent runtime bugs.
Explanation:
Unhandled rejections are dangerous because silent failures can hide critical runtime bugs.
Correct Answer: a) In Node.js, `process.nextTick()` callbacks are queued in the nextTick queue, which runs *even before* standard Promise microtasks.
Explanation:
Node's nextTick queue has the highest priority of all microtask queues in the Node event loop.
Correct Answer: a) A higher-order wrapper function that catches asynchronous failures and re-attempts execution up to a maximum number of attempts
Explanation:
Retry wrappers enhance application resilience against transient failures.
Correct Answer: a) `Array.prototype.forEach` does not wait for async callbacks or `await`; a standard `for...of` loop should be used instead for sequential async operations.
Explanation:
forEach ignores return values and async functions, completing immediately without waiting.
Correct Answer: a) Mapping items to async functions produces an array of promises, which can then be passed to `Promise.all()` to execute concurrently.
Explanation:
Array.map combined with Promise.all is the classic idiom for parallel async mapping.
Correct Answer: a) A state where two or more asynchronous operations are waiting indefinitely for each other to release resources or resolve
Explanation:
Deadlocks occur in poorly synchronized resource locking across async tasks.
Correct Answer: a) To asynchronously transmit small amounts of analytics or diagnostic data to a server safely, even as the user navigates away
Explanation:
sendBeacon uses the browser background queue to ensure telemetry data transmits during page unloads.
Correct Answer: a) A declarative data stream representation that can emit multiple values over time to multiple subscribers, unlike single-value Promises
Explanation:
Observables handle streams of multiple asynchronous events over time.
Correct Answer: a) The promise returned by `.then()` automatically rejects with the thrown error.
Explanation:
Exceptions thrown inside `.then` or `.catch` handlers result in rejection of the chained promise.
Correct Answer: a) Both fulfill successfully, but `Promise.all` returns an array of raw values, whereas `Promise.allSettled` returns an array of status objects.
Explanation:
The output schemas differ: raw values vs `{status, value/reason}` objects.
Correct Answer: a) A design pattern where named events can be triggered and listened to asynchronously using event listener callbacks
Explanation:
Event emitters manage pub-sub event dispatching.
Correct Answer: a) It reclaims memory occupied by objects and closures once they are no longer reachable or referenced by active execution contexts or lingering async listeners.
Explanation:
Garbage collection cleans up unreferenced memory, though dangling listeners can prevent collection.
Correct Answer: a) Invoking an async function or promise without awaiting its result or attaching error handlers
Explanation:
Fire-and-forget runs async tasks in the background without waiting for completion, risking unhandled rejections.
Correct Answer: a) The second catch handles any errors thrown or rejections produced within the first catch handler
Explanation:
Catch handlers return resolved promises unless they throw an error, allowing subsequent catches to handle errors.
Correct Answer: a) Throttling executes at a regular fixed rate over time, whereas debouncing waits for a quiet pause in events before executing once.
Explanation:
Throttle guarantees regular pulses; debounce groups bursts into a single trailing execution.
Correct Answer: a) It allows writing asynchronous code that looks and behaves like synchronous code, improving readability and simplifying complex try/catch error handling.
Explanation:
Async/await syntactic sugar flattens promise chains and simplifies control flow.
Correct Answer: a) No, using `await` outside of an async function or top-level module throws a SyntaxError.
Explanation:
Standard global scripts do not support top-level await unless configured as ES modules.
Correct Answer: a) To coordinate exclusive access to resources across asynchronous workers or tabs
Explanation:
Locks prevent concurrent data corruption in shared storage or worker databases.
Correct Answer: a) The timers phase of the Libuv event loop
Explanation:
Libuv event loop processes expired setTimeout and setInterval callbacks in the timers phase.
Correct Answer: a) It rejects with an `AggregateError` containing all individual rejection reasons.
Explanation:
AggregateError bundles all rejections when Promise.any fails to find any successful fulfillment.
Correct Answer: a) By passing the timer identifier to `clearTimeout(timerId)`
Explanation:
clearTimeout removes the scheduled timer callback from the timer list before execution.
Correct Answer: a) By passing the interval identifier to `clearInterval(intervalId)`
Explanation:
clearInterval stops further recurring executions of the interval callback.
Correct Answer: a) It allows frameworks to batch multiple state mutations and flush DOM updates once at the end of the current execution tick before rendering.
Explanation:
Microtask queuing is a primary mechanism for efficient state batching in modern frontend frameworks.
Correct Answer: a) A protocol defining how objects implement `[Symbol.asyncIterator]()` returning an async iterator with `next()` returning a promise
Explanation:
Async iterables enable asynchronous streaming loops via `for await...of`.
Correct Answer: a) A Promise resolving to 20
Explanation:
The `.then()` handler returns a new promise that resolves with the return value of the callback.
Correct Answer: a) The outer promise returned by `.then()` adopts the state and settlement value of the returned inner Promise (promise flattening).
Explanation:
Promise chaining automatically flattens nested promises.
Correct Answer: a) Forgetting to remove event listeners or clear timers when components or objects are unmounted, keeping them referenced in memory.
Explanation:
Lingering timers and event listeners retain closures in memory, causing leaks.
Correct Answer: a) A synchronization construct that limits the number of concurrent accesses to a shared resource to a fixed maximum count
Explanation:
Semaphores control concurrency pools across asynchronous tasks.
Correct Answer: a) Synchronous exceptions are caught by local try/catch blocks, whereas asynchronous exceptions require error-first arguments or promise .catch() / async try/catch.
Explanation:
Callbacks executed later in the event loop fall outside synchronous try/catch blocks on the initial stack.
Correct Answer: a) It allows flushing pending microtasks to assert promise resolution states deterministically in test assertions
Explanation:
Microtask flushing helps ensure promise chains settle before running assertions.
Correct Answer: a) High throughput and scalability for I/O-bound operations without spawning expensive threads per client connection
Explanation:
Non-blocking I/O allows Node.js to handle thousands of concurrent connections efficiently on a single thread.
Correct Answer: a) It immediately settles with that promise's value or reason.
Explanation:
Race resolves instantly if any input promise is already settled.
Correct Answer: a) A utility that chains multiple asynchronous functions together, passing the resolved output of one function as the input to the next
Explanation:
Async pipe/compose utilities enable functional composition of asynchronous steps.
Correct Answer: a) Alerts 5
Explanation:
An async function returning 5 resolves its returned promise with 5.
Correct Answer: a) If the inner promise rejects, it might result in an unhandled rejection if not caught, and caller functions won't wait for completion unless awaited.
Explanation:
Forgetting to await or return inner promises breaks async control flow and error propagation.
Correct Answer: a) It continuously inspects the call stack and task queues, coordinating the execution of synchronous code, microtasks, and macrotasks.
Explanation:
The event loop is the coordinator enabling asynchronous orchestration in single-threaded runtimes.
Correct Answer: a) Yes, any value yielded in an async generator is automatically wrapped in a resolved promise.
Explanation:
Async generators normalize all yielded values into promises.
Correct Answer: a) To return an object containing a new Promise and its corresponding resolve and reject functions, avoiding scoping separation issues
Explanation:
Promise.withResolvers simplifies creating deferred promises by returning { promise, resolve, reject } together.
Related Posts
New
New
New

Python Strings MCQs
In Python, a string (str) is an immutable sequence of Unicode characters used to represent text data. Defined using single,…
August 27, 2026By MCQs Generator

JavaScript DOM Manipulation MCQs
The Document Object Model (DOM) is a cross-platform programming interface that treats HTML and XML documents as a hierarchical tree…
August 29, 2026By MCQs Generator

JavaScript Error Handling MCQs for Developer Interviews & Certification
Exception and error handling in JavaScript is essential for preventing runtime crashes and maintaining application stability across complex web environments.…
August 29, 2026By MCQs Generator
Related Categories
New












AI & Data Science MCQ
5 topics
By MCQs Generator
New
Arts & Humanities MCQ
4 topics
By MCQs Generator
New
Civil Engineering MCQ
4 topics
By MCQs Generator
New
Commerce & Business MCQ
4 topics
By MCQs Generator
New
Competitive Exams MCQ
5 topics
By MCQs Generator
New
Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator
New
General Knowledge MCQ
2 topics
By MCQs Generator
New
General Science MCQ
4 topics
By MCQs Generator
New
Law & Judiciary MCQ
3 topics
By MCQs Generator
New
Mechanical Engineering MCQ
4 topics
By MCQs Generator
New
Medical & Health Sciences MCQ
4 topics
By MCQs Generator
New
Modern Tech Fields MCQ
3 topics
By MCQs Generator