Home
← All questions

Output question: Promise.all with a rejection in JavaScript

MediumPremiumJavaScript

JavaScript interview practice: What does Promise.all do when one promise rejects?

Problem

const p1 = new Promise((resolve) => setTimeout(() => resolve("P1 resolved"), 1000));
const p2 = new Promise((resolve) => setTimeout(() => resolve("P2 resolved"), 2000));
const p3 = new Promise((_, reject) => setTimeout(() => reject("P3 rejected"), 500));

Promise.all([p1, p2, p3])
  .then(console.log)
  .catch(console.error);
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium