Typefully

JavaScript Promise Methods

Avatar

Share

 • 

3 years ago

 • 

View on X

🧵 JavaScript Promise methods 🧵 In this thread we will learn how to compile the results from the multiple async operations using the following methods: ⬇️ ▶️ Promise.all() ▶️ Promise.race() ▶️ Promise.any() ▶️ Promise.allSettled()
▶️ Promise.all() It takes the array of the promises and gives the following output 👇 - If all promises are resolved then output is the array of resolved promises. - If even one of the promises is rejected it gives the output of the first rejected promise.
▶️ Promise.race() It takes an array of promises and returns the promise's value, depending on which one is resolved or rejected first.
▶️ Promise.any() It returns the value of the promise that is resolved first even if there is some promise which is rejected. It will return the value of the first resolved promise.
▶️ Promise.allSettled() It returns a new promise that resolves when every input promise has settled with an array of objects that describes the result of each promise in the iterable object.
Avatar

Vansh Sharma

@Vanshsh2701

Frontend Engineer @ Seventh Triangle Consulting || books 💛 || Author @Educative