Promise.allSettled in JavaScript

Level 4185 keystrokes

Waits for every promise to finish and reports each one as fulfilled or rejected.

JavaScript code

1const ok = Promise.resolve(1);
2const bad = Promise.reject("no");
// allSettled never rejects; it waits for both promises and collects every outcome
3Promise.allSettled([ok, bad]).then((list) => {
4 list.forEach((r) => {
// A fulfilled result has value and a rejected one has reason, so this prints fulfilled 1, then rejected no
5 console.log(r.status, r.value ?? r.reason);
6 });
7});

Output

fulfilled 1
rejected no
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • .× 9
  • (× 8
  • )× 8
  • ;× 5
  • =× 4
  • ,× 2
  • ?× 2
  • "× 2
  • {× 2
  • }× 2

More JavaScript examples at level 4

← JavaScript typing practice