Skip to content
QuiznExam

Asynchronous JavaScript & Promises Quiz – 15 Questions with Answers

Test your knowledge of asynchronous JavaScript and Promises with 15 questions covering callbacks, Promises, Promise states, then, catch, finally, chaining, and Promise combinators.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. What does asynchronous programming allow JavaScript to do?

    • A. Wait for every operation before executing any other code
    • B. Perform operations without blocking the continuation of other work
    • C. Disable the event loop
    • D. Execute all code simultaneously on separate threads
    Show answer

    B. Perform operations without blocking the continuation of other work

    Asynchronous programming allows JavaScript to start an operation and continue handling other work while waiting for the asynchronous operation to complete.

  2. 2. Which of the following is commonly used to handle asynchronous operations in JavaScript?

    • A. Promises
    • B. Interfaces
    • C. Namespaces
    • D. Structs
    Show answer

    A. Promises

    Promises provide a standard way to represent the eventual completion or failure of an asynchronous operation.

  3. 3. What are the three states of a JavaScript Promise?

    • A. Started, Running, Finished
    • B. Pending, Fulfilled, Rejected
    • C. Open, Closed, Error
    • D. Waiting, Executing, Stopped
    Show answer

    B. Pending, Fulfilled, Rejected

    A Promise starts in the pending state and eventually becomes either fulfilled or rejected.

  4. 4. Which method is used to handle the successful fulfillment of a Promise?

    • A. catch()
    • B. then()
    • C. error()
    • D. success()
    Show answer

    B. then()

    The then() method registers handlers that can be executed when a Promise is fulfilled.

  5. 5. Which method is commonly used to handle a rejected Promise?

    • A. catch()
    • B. reject()
    • C. error()
    • D. fail()
    Show answer

    A. catch()

    The catch() method registers a rejection handler for a Promise chain.

  6. 6. Which method can be used to run cleanup code after a Promise settles, regardless of whether it fulfills or rejects?

    • A. always()
    • B. finally()
    • C. cleanup()
    • D. complete()
    Show answer

    B. finally()

    Promise.prototype.finally() runs a callback after the Promise settles, whether it is fulfilled or rejected.

  7. 7. Which constructor is used to create a new Promise?

    • A. new Promise()
    • B. Promise.create()
    • C. Promise.new()
    • D. create Promise()
    Show answer

    A. new Promise()

    A Promise can be created using the Promise constructor, such as new Promise((resolve, reject) => { ... }).

  8. 8. Which functions are provided to settle a Promise created with the Promise constructor?

    • A. start and stop
    • B. resolve and reject
    • C. success and error
    • D. complete and fail
    Show answer

    B. resolve and reject

    The executor function passed to a Promise constructor receives resolve and reject functions that settle the Promise as fulfilled or rejected.

  9. 9. What happens when a Promise is fulfilled?

    • A. Its fulfillment value becomes available to handlers such as then()
    • B. It automatically becomes rejected
    • C. It returns undefined in every case
    • D. It can return to the pending state
    Show answer

    A. Its fulfillment value becomes available to handlers such as then()

    When a Promise is fulfilled, its resulting value can be received by fulfillment handlers registered with then().

  10. 10. What happens when a Promise is rejected?

    • A. It automatically becomes fulfilled
    • B. Its rejection reason can be handled by catch()
    • C. It returns to the pending state
    • D. It is automatically retried
    Show answer

    B. Its rejection reason can be handled by catch()

    A rejected Promise contains a rejection reason that can be handled using catch() or an appropriate rejection handler.

  11. 11. What is Promise chaining?

    • A. Running only one Promise in an application
    • B. Linking multiple asynchronous operations using successive then() calls
    • C. Creating multiple JavaScript files
    • D. Converting every Promise into a callback
    Show answer

    B. Linking multiple asynchronous operations using successive then() calls

    Promise chaining allows the result of one asynchronous operation to be passed into the next operation through successive then() calls.

  12. 12. Which Promise method waits for all input Promises to fulfill and returns their results?

    • A. Promise.all()
    • B. Promise.any()
    • C. Promise.race()
    • D. Promise.some()
    Show answer

    A. Promise.all()

    Promise.all() fulfills when all input Promises fulfill and provides their fulfillment values in an array. It rejects when an input Promise rejects.

  13. 13. What does Promise.race() do?

    • A. Waits for every Promise to fulfill
    • B. Settles with the first input Promise that settles
    • C. Rejects all input Promises
    • D. Returns only the last Promise result
    Show answer

    B. Settles with the first input Promise that settles

    Promise.race() settles as soon as the first input Promise settles, whether that Promise fulfills or rejects.

  14. 14. What is a callback function in asynchronous JavaScript?

    • A. A function passed to another function to be called later
    • B. A function that can never return a value
    • C. A special JavaScript class
    • D. A function that runs only during compilation
    Show answer

    A. A function passed to another function to be called later

    A callback is a function supplied to another function so it can be invoked later, commonly after an asynchronous operation completes.

  15. 15. Which statement best describes the relationship between Promises and callbacks?

    • A. Promises provide a structured abstraction for representing asynchronous results and can reduce deeply nested callback code
    • B. Promises completely eliminate callbacks from JavaScript
    • C. Callbacks can only be used with synchronous code
    • D. Promises and callbacks are exactly the same mechanism
    Show answer

    A. Promises provide a structured abstraction for representing asynchronous results and can reduce deeply nested callback code

    Promises provide a structured way to represent eventual success or failure and support chaining, which can make complex asynchronous workflows easier to manage.