JavaScript
/Advanced
Promise.all / race / any / allSettled
Definition
Static methods on the Promise object that allow you to handle multiple asynchronous operations simultaneously, rather than awaiting them one by one.
Explain Like I'm New
Imagine sending 3 friends out to grab food. `Promise.all`: You wait until ALL friends return before eating. If one gets a flat tire (rejects), dinner is ruined. `Promise.race`: You eat the food of whoever gets back FIRST. `Promise.any`: You eat the first food that arrives safely, ignoring flat tires. `Promise.allSettled`: You wait for everyone to return, whether they brought food or excuses.
Real World Example
Using `Promise.all` to fetch data from three completely independent APIs at the exact same time, cutting a 6-second total loading time down to 2 seconds.
Common Use Cases
- •Parallel execution
- •Performance optimization
- •Graceful failure handling
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- Why is `Promise.all` faster than sequential `await`?
intermediate
- What happens if one Promise in `Promise.all` rejects?
advanced
- When would you choose `Promise.allSettled` over `Promise.all`?