Async/Await

Preview — 3 of 10 questions

What best describes a Promise in JavaScript?

javascript
const promise = new Promise((resolve, reject) => {
  setTimeout(() => resolve("Done!"), 1000);
});

promise.then((result) => console.log(result)); // "Done!" after 1s
AA function that always executes asynchronously
BAn object representing the eventual completion or failure of an asynchronous operation
CA callback function used for event handling
DA built-in JavaScript method for handling timeouts

What are the three possible states of a Promise?

APending, Resolved, Rejected
BInitial, Processing, Completed
CPending, Fulfilled, Rejected
DLoading, Success, Failure

What will the following code output?

javascript
Promise.resolve(1)
  .then((value) => value + 1)
  .then((value) => {
    throw new Error("Error occurred");
  })
  .catch((error) => console.log("Caught:", error.message));
A2
BCaught: Error occurred
Cundefined
DError thrown and stops execution

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.