JavaScript Interview Question #86
What does Promise.all() do?
Promises, Async/Await, Fetch & Modern JavaScript Mid-Level Intermediate
Quick Interview Answer
Promise.all accepts an iterable of values or Promises and returns a Promise that fulfills when all inputs fulfill. The fulfilled result is an array preserving the input order.
Detailed Explanation
Promise.all accepts an iterable of values or Promises and returns a Promise that fulfills when all inputs fulfill. The fulfilled result is an array preserving the input order.
If any input Promise rejects, the Promise returned by Promise.all rejects with that reason. This is appropriate when all operations are required for the overall task to succeed.
Code Example
const [user, orders, notifications] =
await Promise.all([
getUser(),
getOrders(),
getNotifications()
]);
console.log(user, orders, notifications);