DEV Community

Discussion on: The new features of Javascript in 2020 (ES11)

Collapse
 
king11 profile image
Lakshya Singh

Didn't we already have a Promise.all() what's the difference

Collapse
 
sireaev profile image
sirev

Yes, we did. The difference is that Promise.all() didn't resolve the promises from array in then if it had at least one rejected.

Promise.all([Promise.resolve('resolved'), Promise.reject('rejected')]).then((r) => console.log(r)).catch(() => console.log('catch here!'));
Output
// catch here!

Promise.allSettled([Promise.resolve('resolved'), Promise.reject('rejected')]).then((r) => console.log(r)).catch(() => console.log('catch here!'));

Output
// [
// { status: "fulfilled", value: 'resolved' },
// { status: "rejected", reason: 'rejected' }
// ]

Collapse
 
king11 profile image
Lakshya Singh

Ohh cool thanks for clarifying :))