---
title: "Async JavaScript: Promises, Async/Await, Event Loop"
description: "Master asynchronous JavaScript: callbacks, Promises, async/await, event loop, microtasks. Essential for modern backend and frontend development."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/async-javascript-promises-quiz
---

# Async JavaScript: Promises, Async/Await, Event Loop

Welcome to the Async JavaScript quiz! Test your knowledge of Promises, async/await, the event loop, and advanced concurrency patterns. Each question has a hint and detailed explanations for all options. Good luck!

## Questions

### 1. What is the JavaScript event loop?

- The mechanism that monitors the call stack and moves tasks from the callback queue to the stack
- A background process that parallelizes JavaScript execution across multiple CPU cores
- A built-in garbage collection routine that clears unused variables from the heap during idle time
- A network synchronization tool used to coordinate data between the browser and the server

**Hint:** Think about asynchronous execution.

### 2. What is a callback function?

- A function passed into another function as an argument to be executed at a later time
- A specialized function that automatically retries an operation if it fails to resolve
- A reserved keyword used to return the result of an asynchronous operation to the global scope
- A native method used to trigger the immediate termination of a running asynchronous process

**Hint:** Think about a function passed to another function.

### 3. What is callback hell?

- A situation where deeply nested callbacks make code difficult to read and manage errors
- An execution error occurring when a recursive function exceeds the maximum call stack size
- A memory leak caused by retaining references to functions that are no longer being used
- A race condition where multiple callbacks attempt to update the same global state simultaneously

**Hint:** Think about deeply nested callbacks.

### 4. What is a Promise?

- An object representing the eventual completion or failure of an asynchronous operation
- A synchronous wrapper that forces an asynchronous function to return an immediate value
- A global event emitter used to broadcast state changes across different parts of an application
- A browser-only API designed to handle communication between different windows or tabs

**Hint:** Think about representing a future value.

### 5. What does Promise.resolve() do?

- Returns a Promise object that is resolved with a specified value or result
- Immediately triggers the .then() block of every pending Promise in the current queue
- Converts a synchronous function into an asynchronous one without changing its return type
- Clears all rejected Promises from the microtask queue to prevent application crashes

**Hint:** Think about returning a resolved Promise.

### 6. What does Promise.reject() do?

- Returns a Promise object that is rejected with a given reason or error message
- Terminates the execution of the current script to prevent further async operations
- Prevents a Promise from ever settling to ensure that its callbacks are never executed
- Automatically triggers a retry of the asynchronous operation using backoff logic

**Hint:** Think about returning a rejected Promise.

### 7. What is an async function?

- A function that always returns a Promise and allows the use of the await keyword
- A specialized function that runs on a separate thread to avoid blocking the UI
- A function that executes immediately and pauses the event loop until it completes
- A reserved constructor used to create new asynchronous classes in modern JavaScript

**Hint:** Think about syntactic sugar for Promises.

### 8. What is the purpose of the await keyword?

- Pauses the execution of an async function until a Promise settles and returns its result
- Speeds up the execution of multiple Promises by running them in parallel threads
- Directly converts a Promise into a synchronous value available in the global scope
- Forces the event loop to prioritize the current task over all other pending microtasks

**Hint:** Think about pausing execution.

### 9. How does Promise.all() behave?

- Fulfills when all input Promises fulfill, but rejects immediately if any Promise rejects
- Fulfills as soon as the first Promise resolves, regardless of the state of others
- Executes a list of asynchronous functions one after another in a strict sequential order
- Returns an array of results only after every Promise has either fulfilled or rejected

**Hint:** Think about waiting for multiple Promises.

### 10. What is the behavior of Promise.race()?

- Returns a Promise that settles as soon as any of the input Promises fulfill or reject
- Waits for all Promises to complete and returns the one that took the least time
- Rejects only if all of the provided Promises fail to resolve within a given timeout
- Prioritizes the fastest network request while cancelling all other slower operations

**Hint:** Think about the first settled Promise.

### 11. What is the microtask queue?

- A high-priority queue for Promises and MutationObservers processed before the next macrotask
- A low-priority queue used for UI rendering and handling user input events like clicks
- A temporary storage area for variables that are passed between different Web Workers
- A debugging tool used to track the memory allocation of small objects in the heap

**Hint:** Think about Promise callback timing.

### 12. How does setTimeout interact with the event loop?

- It schedules a callback to be executed as a macrotask after the current stack and microtasks
- It pauses the event loop for a set duration to ensure no other code executes
- It injects a function directly into the microtask queue for immediate execution
- It bypasses the event loop to execute code on a separate background system thread

**Hint:** Think about macrotask timing.

### 13. What is error handling with async/await?

- The use of try/catch blocks to capture and handle errors from awaited Promises
- The mandatory use of the .onerror() property on all asynchronous function declarations
- A global monitoring system that automatically suppresses all asynchronous rejections
- The practice of returning null instead of throwing an error when an operation fails

**Hint:** Think about try/catch.

### 14. What is the use case for Promise.allSettled()?

- When you need to wait for all operations to complete regardless of their individual success or failure
- When you want to stop the execution of a batch of Promises as soon as any one of them fails
- When you need to find the fastest successful response from a group of mirrored API endpoints
- When you are working with legacy callback-based code that does not support modern error objects

**Hint:** Think about all Promises without early rejection.

### 15. What is the behavior of Promise.any()?

- It returns the first Promise that fulfills, and only rejects if every input Promise rejects
- It returns the first Promise that settles, whether it was a success or a rejection
- It combines the results of all fulfilled Promises into a single aggregate success object
- It cancels all pending Promises once any of the input Promises has successfully resolved

**Hint:** Think about the first fulfilled Promise.

### 16. What is the role of the Promise constructor?

- It creates a new Promise where an executor function manually controls the resolve and reject calls
- It is a specialized utility used to merge two existing Promises into a single new instance
- It acts as a decorator that automatically adds timeout logic to any synchronous function
- It defines a template for asynchronous classes to ensure they implement a standard .then() method

**Hint:** Think about creating a new Promise manually.

### 17. What is Promise chaining?

- A pattern where each .then() returns a new Promise, allowing for sequential async operations
- A method of linking multiple Promises together so they all resolve at exactly the same time
- A memory optimization that allows multiple Promises to share the same underlying result object
- A security feature that prevents a Promise from being accessed by unauthorized scripts

**Hint:** Think about .then() returning a new Promise.

### 18. What is the unhandledrejection event?

- A global event fired when a Promise is rejected and no rejection handler is attached to it
- A syntax error triggered during development when a Promise constructor is missing an executor
- A network event that occurs when a server fails to respond to a fetch request within the timeout
- A cleanup routine that runs automatically to close connections when an async function crashes

**Hint:** Think about catching Promise errors.

### 19. What is the AbortController API?

- An interface that allows you to abort one or more Web requests or asynchronous operations
- A specialized debugger used to stop the execution of the event loop for inspection
- A resource management tool that automatically deletes old Promises from the memory heap
- A middleware component used to reject incoming HTTP requests based on their payload size

**Hint:** Think about cancelling fetch/async operations.

### 20. What is the primary function of the Fetch API?

- A modern, Promise-based interface for making network requests and handling responses
- A server-side utility used to scrape HTML content from external websites for indexing
- A synchronous data retrieval method that blocks code execution until a file is downloaded
- An internal browser routine that pre-loads images to improve the speed of page rendering

**Hint:** Think about Promise-based HTTP requests.

### 21. What is an async iterator?

- An object that implements the Symbol.asyncIterator method for use with for-await-of loops
- A function that automatically iterates through an array and executes each item in parallel
- A specialized loop that allows synchronous functions to be executed inside an async context
- A data structure that stores asynchronous results in a first-in, first-out sequence

**Hint:** Think about for-await-of loops.

### 22. What is the difference between concurrent and sequential execution?

- Concurrent runs independent tasks in parallel; sequential waits for each task to finish before starting the next
- Concurrent is always safer for database writes; sequential is faster for read-only operations
- Concurrent execution requires Web Workers; sequential execution is the only mode for the main thread
- Concurrent refers to nested callbacks; sequential refers to the use of modern async/await syntax

**Hint:** Think about Promise.all() vs awaiting one by one.

### 23. What is top-level await?

- The ability to use the await keyword at the highest level of a module without an async function
- A performance optimization that lifts all await calls to the top of the call stack for faster execution
- A specialized error handling mode that catches all rejections at the top level of the window object
- A global setting that forces all functions in a script to act as if they were declared as async

**Hint:** Think about await in module scope.

### 24. What is async context preservation?

- Ensuring that "this" and other closure variables remain accessible across asynchronous boundaries
- A memory management technique that keeps local variables from being garbage collected
- A security policy that prevents asynchronous functions from accessing the global window scope
- The practice of saving the current state of a Promise to a local file in case of a crash

**Hint:** Think about context loss with async.

### 25. What is the retry pattern in asynchronous code?

- A strategy of wrapping async calls in a loop with error handling and exponential backoff
- A recursive function that re-executes itself immediately whenever any variable changes state
- A database configuration that automatically restores deleted records from a transaction log
- An optimization that caches successful results to avoid making the same request twice

**Hint:** Think about retrying failed requests.

### 26. What is a typical use case for Promise.allSettled()?

- Handling a batch of independent operations where partial success is acceptable and results must be tracked
- Ensuring that a critical sequence of financial transactions stops immediately if one step fails
- Improving the performance of a single large file upload by splitting it into smaller chunks
- Translating synchronous XML requests into a modern JSON format for use in older browsers

**Hint:** Think about batch operations with failures.

### 27. What is the purpose of debouncing an asynchronous operation?

- To limit the rate at which a function executes by waiting for a period of inactivity before triggering
- To encrypt asynchronous data payloads before they are transmitted over a public network
- To ensure that two different asynchronous operations do not access the same memory address
- To automatically increase the priority of a Promise so it resolves faster under heavy load

**Hint:** Think about delaying async operations.

### 28. How is Promise.then() return value transformed?

- If the handler returns a value, the new Promise resolves to that value; if it returns a Promise, it waits for it
- The return value is ignored, and the new Promise always resolves with the original value from the first Promise
- The return value is immediately converted into a string to ensure type safety in the next link of the chain
- Returning any value from a .then() block causes the entire Promise chain to reject with a TypeError

**Hint:** Think about transforming Promise results.

### 29. What are asynchronous cleanup patterns?

- Using try/finally blocks to ensure that resources like timers and connections are closed regardless of success
- The use of a global garbage collector that identifies and deletes pending Promises every sixty seconds
- A specialized syntax that automatically deletes all variables at the end of every async function
- A process of overwriting sensitive data with null values before a Promise is allowed to settle

**Hint:** Think about cleaning up resources in async code.

### 30. What are generator functions?

- Functions that can be exited and later re-entered, with their context preserved across multiple re-entries
- Specialized constructors used to generate random data sets for performance and load testing
- An internal engine routine that generates optimized machine code from high-level JavaScript
- A type of asynchronous function that automatically parallelizes loops for increased performance

**Hint:** Think about functions that can pause and resume.
