Skip to content
QuiznExam

Async / Await in JavaScript Quiz – 15 Questions with Answers

Test your knowledge of async and await in JavaScript with 15 questions covering asynchronous functions, Promises, error handling, execution flow, and common async programming patterns.

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 the async keyword do when used before a JavaScript function?

    • A. It makes the function execute synchronously
    • B. It makes the function always return a Promise
    • C. It stops the function from returning a value
    • D. It converts the function into a callback
    Show answer

    B. It makes the function always return a Promise

    An async function always returns a Promise. If it returns a value, the Promise is fulfilled with that value.

  2. 2. Where can the await keyword normally be used?

    • A. Only inside an async function
    • B. Only inside a callback
    • C. Only inside a class
    • D. Only inside a loop
    Show answer

    A. Only inside an async function

    The await keyword can normally be used inside async functions. Modern JavaScript also supports top-level await in appropriate modules.

  3. 3. What does await do when used with a Promise?

    • A. It converts the Promise into a callback
    • B. It waits for the Promise to settle and produces its fulfillment value
    • C. It immediately rejects the Promise
    • D. It creates a new Promise
    Show answer

    B. It waits for the Promise to settle and produces its fulfillment value

    await pauses execution of the surrounding async function until the Promise settles. If fulfilled, it evaluates to the fulfillment value.

  4. 4. What happens if an async function returns a normal value such as 10?

    • A. It returns 10 directly
    • B. It returns undefined
    • C. It returns a Promise fulfilled with 10
    • D. It throws an error
    Show answer

    C. It returns a Promise fulfilled with 10

    Values returned from async functions are automatically wrapped in a fulfilled Promise.

  5. 5. Which statement correctly handles a rejected Promise when using await?

    • A. Use try...catch
    • B. Use if...else only
    • C. Use switch only
    • D. Use for...in
    Show answer

    A. Use try...catch

    A rejected Promise awaited inside an async function throws an exception at the await expression, which can be handled using try...catch.

  6. 6. What will this code return? async function test() { return 42; }

    • A. 42
    • B. A Promise fulfilled with 42
    • C. undefined
    • D. A rejected Promise
    Show answer

    B. A Promise fulfilled with 42

    Because test is an async function, its return value is wrapped in a Promise.

  7. 7. What happens when await is used on a non-Promise value?

    • A. It always throws an error
    • B. The value is treated as an already fulfilled result
    • C. The value becomes undefined
    • D. The program terminates
    Show answer

    B. The value is treated as an already fulfilled result

    await can be used with non-Promise values. The value is effectively treated as an already fulfilled result.

  8. 8. Which code correctly uses async and await?

    • A. async function getData() { const data = await fetch(url); return data; }
    • B. async getData() { wait fetch(url); }
    • C. function async getData() { await fetch(url); }
    • D. await async function getData() { fetch(url); }
    Show answer

    A. async function getData() { const data = await fetch(url); return data; }

    The async keyword declares the function as asynchronous, and await is used inside it to wait for the Promise returned by fetch.

  9. 9. What is a major benefit of async/await compared with directly chaining multiple then() calls?

    • A. It removes the need for Promises
    • B. It can make asynchronous code easier to read and reason about
    • C. It makes all JavaScript code synchronous
    • D. It eliminates all runtime errors
    Show answer

    B. It can make asynchronous code easier to read and reason about

    Async/await provides syntax that resembles synchronous control flow while still working with Promises.

  10. 10. If an awaited Promise is rejected and there is no matching try...catch inside the async function, what happens?

    • A. The async function returns a fulfilled Promise
    • B. The rejection is ignored
    • C. The async function's returned Promise becomes rejected
    • D. The Promise automatically retries
    Show answer

    C. The async function's returned Promise becomes rejected

    A rejected awaited Promise throws inside the async function. If the error is not caught, the async function returns a rejected Promise.

  11. 11. What is a potential performance issue with writing multiple independent await statements sequentially?

    • A. Independent operations may unnecessarily wait for one another
    • B. Promises cannot be created
    • C. The JavaScript engine stops permanently
    • D. All operations become CPU-bound
    Show answer

    A. Independent operations may unnecessarily wait for one another

    If independent asynchronous operations are awaited one after another, later operations may not start until earlier ones finish. Promise.all can often be used to run independent operations concurrently.

  12. 12. Which method is commonly used with async/await to wait for multiple independent Promises concurrently?

    • A. Promise.all()
    • B. Promise.single()
    • C. Promise.wait()
    • D. Promise.concurrentOnly()
    Show answer

    A. Promise.all()

    Promise.all() can be awaited to wait for multiple Promises to fulfill while allowing the operations to be started without sequential waiting.

  13. 13. What does an async function return when an exception is thrown inside it and the exception is not caught?

    • A. A fulfilled Promise
    • B. A rejected Promise
    • C. The exception value directly
    • D. Always null
    Show answer

    B. A rejected Promise

    An uncaught exception inside an async function causes the Promise returned by that function to be rejected.

  14. 14. Which statement about await is correct?

    • A. await blocks the entire JavaScript runtime until the Promise finishes
    • B. await pauses only the execution of the surrounding async function while the Promise settles
    • C. await converts JavaScript into a multithreaded language
    • D. await can only be used with fetch()
    Show answer

    B. await pauses only the execution of the surrounding async function while the Promise settles

    await suspends the surrounding async function's execution while allowing the JavaScript environment to continue handling other work.

  15. 15. Which pattern is generally appropriate for handling both successful and failed asynchronous operations?

    • A. try...catch
    • B. switch...case
    • C. for...in
    • D. do...while
    Show answer

    A. try...catch

    A try...catch block can handle errors thrown by awaited rejected Promises, allowing asynchronous success and failure paths to be handled clearly.