What is the output of the following? “`js const p1 = Promise.resolve(1); const p2 = Promise.reject(new Error(‘fail’)); const p3 = Promise.resolve(3); Promise.allSettled([p1, p2, p3]).then(results => { console.log(results.length); }); “`

JavaScript Developer Hard

JavaScript Developer — Hard

What is the output of the following? “`js const p1 = Promise.resolve(1); const p2 = Promise.reject(new Error(‘fail’)); const p3 = Promise.resolve(3); Promise.allSettled([p1, p2, p3]).then(results => { console.log(results.length); }); “`

Key points

  • `Promise.allSettled` includes all promises in the results array
  • The length of the results array includes all promises, whether resolved or rejected
  • The output is not affected by the rejection of `p2`

Ready to go further?

Related questions