
JavaScript Promises manage future values with clean async handling. Learn how Promise.all, race, allSettled, and any simplify parallel tasks, timeouts, and error management.
Martin Ferret
September 30, 2025
In JavaScript, Promises work like receipts for future values.
When you place an order (make an asynchronous request), you immediately get a receipt (the Promise). The actual item (the resolved value) arrives later.
This model makes asynchronous code easier to read and maintain than nested callbacks. More importantly, Promises enable advanced patterns that help you manage multiple tasks in powerful and efficient ways.
Advanced Promise Patterns
Promise.all: run tasks in parallel and wait for allUse this when you need to start several asynchronous operations and continue only once every single one has completed.
const api1 = fetch("/users");
const api2 = fetch("/posts");
Promise.all([api1, api2])
.then(([users, posts]) => {
console.log("Data loaded:", users, posts);
})
.catch(err => console.error("Error:", err));
Best for: loading multiple resources before rendering a page.
Promise.race: the first one winsThis resolves or rejects as soon as the first Promise settles.
const slow = new Promise(r => setTimeout(() => r("slow"), 2000));
const fast = new Promise(r => setTimeout(() => r("fast"), 500));
Promise.race([slow, fast]).then(value => {
console.log("Result:", value); // "fast"
});
Best for: implementing timeouts.
Promise.allSettled: know the outcome of allUnlike Promise.all, this waits for every Promise to settle, regardless of whether they resolve or reject
const p1 = Promise.resolve("ok");
const p2 = Promise.reject("error");
Promise.allSettled([p1, p2]).then(results => {
console.log(results);
// [
// { status: "fulfilled", value: "ok" },
// { status: "rejected", reason: "error" }
// ]
});
Best for: reporting all results without failing early.
Promise.any: the first successful oneThis returns the first Promise that resolves successfully, ignoring rejections.
const p1 = Promise.reject("fail");
const p2 = new Promise(r => setTimeout(() => r("success"), 1000));
Promise.any([p1, p2]).then(result => {
console.log(result); // "success"
});
Best for: trying multiple strategies (mirrors, fallbacks) and keeping the first valid response.
These patterns are essential for modern applications where asynchronous operations are everywhere.
Get the latest news and updates on developer certifications. Content is updated regularly, so please make sure to bookmark this page or sign up to get the latest content directly in your inbox.

Inside the JavaScript Event Loop: How the Runtime Actually Works
Understand the JavaScript event loop in depth. Learn how the call stack, microtasks, and macrotasks work together to handle asynchronous code efficiently, keeping your applications fast, predictable, and responsive.
Martin Ferret
Nov 18, 2025

React Free Weekend: 48 hours of Open Access to Premium React Certification Training
Every year, we at Certificates.dev look for ways to make our certifications more accessible - not just for teams inside big tech companies, but for every developer who wants to validate their skills through real-world, hands-on learning. That’s why we are excited to announce our first-ever React Free Weekend, taking place on November 15–16, 2025.
Aurora Scharff
Nov 11, 2025

Error Handling in React with react-error-boundary
Learn how to handle errors in React applications with react-error-boundary. Explore fallback UIs, async error handling with useErrorBoundary, and React 19's automatic error boundary integration with form actions and useTransition.
Aurora Scharff
Nov 10, 2025
We can help you recruit Certified Developers for your organization or project. The team has helped many customers employ suitable resources from a pool of 100s of qualified Developers.
Let us help you get the resources you need.
