Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

What happens when one promise in Promise.all rejects?

Do you know what will be the output of this code?

JavaScript
Promise.all([
  Promise.resolve(1),
  Promise.reject(new Error("fail")),
  Promise.resolve(3),
])
  .then((values) => console.log(values))
  .catch((err) => console.log(err.message));
Show answer and explanation

The answer is "fail".

Promise.all is all-or-nothing: it rejects with the first rejection reason and the fulfilled values are discarded. Promise.allSettled waits for every promise and reports each result.

Take the full quiz Next question →

More Promises & Async questions

  1. Why does an arrow function in setTimeout keep this?
  2. Why does a Promise run before setTimeout 0?
  3. What does an async function return in JavaScript?
  4. What runs first after await in JavaScript?
  5. Is the Promise constructor callback synchronous?

Related topics