bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/JavaScript/Objects, Classes, and Advanced Patterns
JavaScript•Objects, Classes, and Advanced Patterns

JavaScript Promise Reference

Concept visual

JavaScript Promise Reference

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

This page is a reference for

JavaScript promises. Use it to look up promise methods and common patterns. If you want to learn promises step by step, read JavaScript Promises.

The Promise Object

The

Promise Object represents the completion or failure of an asynchronous operation. A Promise can have 3 states: pending initial state rejected operation failed fulfilled operation completed

Promise Object Methods

Revised December 2025

Instance Methods

Method

Description.catch(onRejected) Provides a function to run when a promise is rejected.finally(onFinally) Provides a function to run when a promise is fulfilled or rejected.then(onFulfilled, onRejected) Provides two functions to run when a promise is fulfilled

Static Methods

Method

Description

Promise.all() Returns a single Promise from a list of promises

When all promises fulfill

Promise.allSettled() Returns a single Promise from a list of promises

When all promises sette

Promise.any() Returns a single Promise from a list of promises

When any promise fulfills

Promise.race() Returns a single Promise from a list of promises

When the faster promise settles

Promise.reject() Returns a Promise rejected with a given value Promise.resolve() Returns a Promise resolved with a given value Promise.then()

Provides two callbacks:

One funtion to run when a promise is fulfilled. One funtion to run when a promise is rejected. Promise.try() Executes a function and wraps its result in a promise. Promise.withResolvers() Returns an object containing a new Promise object and two functions to resolve or reject it. The .then() Method The.then() method provides two functions to run when a promise is fulfilled.

Example

// Using then() to display a result myPromise.then(

function(value) {myDisplayer(value)}, function(value) {myDisplayer(value)}
);
The .catch() Method
The.catch()

method provides a function to run when a promise is rejected.

Example

// Using catch() to display a result myPromise.catch(

function(value) {myDisplayer(value);}
);
The .finally() Method
The.finally()

method provides a function to run when a promise is fulfilled or rejected.

Example

// Using finally() to display a result myPromise.finally(

function(value) {myDisplayer(value)}
);
Promise.resolve()

The

Promise.resolve() method returns a Promise object resolved with a value.

Example

let promise = Promise.resolve("Resolved OK");
promise.then(function(value) {
myDisplayer(value);
}).catch(function(value) {
myDisplayer(value);
});
Promise.reject()

The

Promise.reject() method returns a Promise object rejected with a value.

Example

let promise = Promise.reject("Something went wrong");
promise.then(function(value) {
myDisplayer(value);
}).catch(function(value) {
myDisplayer(value);
});
Promise.all()

The

Promise.all() method returns a single Promise from a list of promises, when all promises fulfill (or rejects when one promise rejects).

Example

let p1 = Promise.resolve("A");
let p2 = Promise.resolve("B");
Promise.all([p1, p2]).then(function(values) {
myDisplayer(values);
});
Promise.allSettled()
Promise.allSettled() returns an array of results for all promises.

Each result contains a status and a value or reason.

Examples let p1 = Promise.resolve("A");
let p2 = Promise.reject("X");
Promise.allSettled([p1, p2]).then(function(results) {
myDisplayer(JSON.stringify(results));
});
// Create a Promise const myPromise1 = new Promise((resolve, reject) => {
setTimeout(resolve, 200, "King");
});
// Create another Promise const myPromise2 = new Promise((resolve, reject) => {
setTimeout(resolve, 100, "Queen");
});

// Settle All

Promise.all([myPromise1, myPromise2]).then(function(values) {
myDisplayer(values);
});
Promise.allSettled() means "Just run all promises. I don't care about the results".

Previous

Debugging Async JavaScript

Next

JavaScript Modules