Promise.all() vs Promise.allSettled()

1 min read

Both methods run multiple promises in parallel, but they differ in how they handle errors.
Choosing the right one prevents bugs and missing data in real-world apps.

Promise.all()

  • ❌ Stops on the first failure
  • Returns results only if all succeed
  • Best for critical operations
Promise.all([
  fetch("/user"),
  fetch("/orders"),
  fetch("/payments") // ❌ fails
])
.then(results => {
  // never runs
})
.catch(err => {
  console.error("Failed:", err);
});

Promise.allSettled()

  • ✅ Waits for all promises to finish
  • Returns both success and failure results
  • Best for non-critical or batch tasks
Promise.allSettled([
  fetch("/user"),
  fetch("/orders"),
  fetch("/payments") // ❌ fails
])
.then(results => {
  results.forEach((result, index) => {
    if (result.status === "fulfilled") {
      console.log(`Request ${index} success`, result.value);
    } else {
      console.error(`Request ${index} failed`, result.reason);
    }
  });
});

More on JavaScript

Recent Tips

Validate on Backend. Always.

Frontend validation improves user experience. It shows instant errors and prevents obvious mistakes like empty fields or invalid email formats. But frontend validation is never security. Anyone can bypass it using DevTools, Postman, or by directly calling your API. That’s why backend validation is mandatory it protects your database and business logic from invalid or malicious data.