codejump

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
BA built-in JavaScript method for handling timeouts
CA callback function used for event handling
DAn object representing the eventual completion or failure of an asynchronous operation

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
BError thrown and stops execution
Cundefined
DCaught: Error occurred

Sign up free to play

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