Promise
A value representing an operation that hasn't completed yet, eventually settling as fulfilled (success) or rejected (failure).
new Promise((resolve, reject) => {}) / Promise.all([...]) / Promise.resolve(value)
Purpose
A Promise represents a value that isn’t available yet. It starts pending, and settles exactly
once — either fulfilled with a value, or rejected with a reason (usually an Error).
fetch, timers wrapped in a promise, and most modern async APIs return one.
Syntax
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
fetch('/api/data')
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error(error));
const [a, b] = await Promise.all([fetchA(), fetchB()]); // run concurrently
async/await (see async/await) is the more common way to work
with promises today; .then()/.catch() is the underlying mechanism it’s built on and still shows
up in older code and library documentation.
Behavior notes
- A promise settles exactly once — it cannot go from fulfilled back to pending, or from rejected to fulfilled.
Promise.all(promises)resolves once every promise resolves, with an array of their results in order; it rejects immediately if any one of them rejects.Promise.allSettled(promises)(Intermediate tier) resolves once every promise has settled, regardless of success or failure, and reports each outcome individually — useful when partial success should be handled rather than treated as a total failure.Promise.resolve(value)/Promise.reject(reason)create an already-settled promise, useful for matching a function’s return type when a value is already known synchronously.
Common mistakes
- Forgetting that
Promise.allrejects as a whole if any single promise in the group rejects — which can be surprising when the group includes both critical and optional requests. - Mixing
.then()chains withasync/awaitin the same function, making control flow harder to follow than picking one consistently.
Runtime notes
Promise is core ECMAScript, identical across every current browser and Node version.