Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
communitycreator

What is Promise.all() in JavaScript?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The Promise.all() method takes a list of promises as an input and returns a single promise.

The returned promise will resolve once all the promises passed as input are resolved.

When the returned promise is resolved, the resolved values of all promises are returned as an array.

Code

Let’s create two promises and pass them to the Promise.all() method. When all the promises are resolved, we will print the resolved values of all passed promises.

Console

The Promise.all() method rejects when any one of the input promises is rejected. The method will return the rejected promise with the first rejected promise’s message/error.

Console

In the above code, we have three promises. promise2 is rejected, so Promise.all() will return a rejected promise with promise2 as the message.

RELATED TAGS

javascript
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring