DOM Manipulation in JavaScript
15 questions · 12 min · Medium
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.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
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.
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.
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.
C. It returns a Promise fulfilled with 10
Values returned from async functions are automatically wrapped in a fulfilled Promise.
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.
B. A Promise fulfilled with 42
Because test is an async function, its return value is wrapped in a Promise.
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.
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.
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.
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.
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.
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.
B. A rejected Promise
An uncaught exception inside an async function causes the Promise returned by that function to be rejected.
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.
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.