Promise allSettled()

Promise.allSettled() returns an array of promise results, each containing a status (fulfilled or rejected) and the resolved value or rejection reason, facilitating comprehensive promise handling.

Syntax:

Promise.allSettled(iterable);

Example: In this example, we will use Promise allSettled() Method.

Javascript




// Illustration of Promise.allSettled()
// Method in Javascript with Example
  
const p1 = Promise.resolve(50);
const p2 = new Promise((resolve, reject) =>
    setTimeout(reject, 100, 'geek'));
const prm = [p1, p2];
  
Promise.allSettled(prm).
    then((results) => results.forEach((result) =>
        console.log(result.status, result.value)));


Output

fulfilled 50
rejected undefined

Supported browser:

  • Chrome 1
  • Edge 12
  • Firefox 1
  • Safari 1
  • Opera 3


JS 2020 – ECMAScript 2020

JavaScript ECMAScript 2020 (ES11) introduced new features like optional chaining, nullish coalescing, dynamic import(), BigInt, and Promise.allSettled(), etc. enhancing language capabilities for modern web development needs.

JavaScript 2020 (ES11) or ECMAScript 2020 new features are:

BigInt

type for arbitrary precision integers beyond the Number’s limit.

String matchAll()

returns an iterator for all regex matches in the string.

The Nullish Coalescing Operator (??)

returning right operand if the left is nullish, else left.

The Optional Chaining Operator (?.)

accessing nested properties if they exist, otherwise returns undefined.

Logical AND Assignment Operator (&&=)

assigns the right operand to the left if the left is truthy.

Logical OR Assignment (||=)

assigns the right operand if the left is falsy, else left.

Nullish Coalescing Assignment (??=)

the operator assigns the right operand if the left is nullish, else left.

Promise allSettled()

returning an array of promise results with status and value.

Dynamic Import

enables asynchronous import of modules at runtime.

Similar Reads

Method 1: BigInt

BigInt is a built-in object in JavaScript that provides a way to represent whole numbers larger than 253-1....

Method 2: String matchAll() Method

...

Method 3: The Nullish Coalescing Operator (??)

This method returns an iterator of all matches in a string based on a regular expression, facilitating comprehensive pattern matching and data extraction in JavaScript....

Method 4: The Optional Chaining Operator (?.)

...

Method 5: Logical AND Assignment Operator (&&=)

The nullish coalescing operator (??) returns the right operand if the left operand is null or undefined, otherwise, it returns the left operand, enhancing conditional value assignment in JavaScript....

Method 6: Logical OR Assignment (||=)

...

Method 7: Nullish Coalescing Assignment (??=)

The optional chaining operator (?.) allows safe accessing of nested properties and methods in JavaScript objects, preventing errors when properties are undefined or null....

Method 8: Promise allSettled()

...