Skip to content
Latest: The updated version of the Creating NPM Package (React JavaScript) book is out

Promise.resolve() – What Is the JavaScript Promise resolve() Method?

Promise.resolve() is a static method of the Promise constructor function. It returns a new promise object that resolves with the value you’ve passed as its argument.

Syntax of the Promise.resolve() Static Method

Promise.resolve(value);

The Promise.resolve() syntax is a simpler alternative to new Promise(...)—especially when you do not need to use the Promise constructor’s callback argument.

For instance, here’s one way to resolve a promise object to the "I will code sweetly!" string value:

const myPromise = new Promise(function (resolve, reject) {
resolve("I will code sweetly!");
});
console.log(myPromise);
// The invocation above will return:
Promise { <state>: "fulfilled", <value>: "I will code sweetly!" }

You can alternatively use the Promise.resolve() method to simplify your code like so:

const myPromise = Promise.resolve("I will code sweetly!");
console.log(myPromise);
// The invocation above will return:
Promise { <state>: "fulfilled", <value>: "I will code sweetly!" }

Important Stuff to Know about Promise.resolve()

Here are two essential facts to remember while using the Promise.resolve() static method.

Promise.resolve()’s argument determines the resolved value

A promise object’s resolved value depends on the data type you passed as an argument to the resolve() method.

For instance, the promise object in the snippet below resolved to an array value because we passed in an array data type as an argument to the resolve() method.

const myPromise = Promise.resolve(["I will code sweetly"]);
console.log(myPromise);
// The invocation above will return:
Promise { <state>: "fulfilled", <value>: Array ["I will code sweetly!"] }

Promise.resolve() unwraps its argument

Promise.resolve() will always unwrap its argument down to its non-thenable value.

For instance, when the snippet below passed a real promise object to the first Promise.resolve() method, the Promise.resolve() method unwrapped the promise object down to its non-thenable value. Therefore, the resultant promise object resolved to the "I will code sweetly!" string value.

const myPromise = Promise.resolve(
Promise.resolve(
Promise.resolve("I will code sweetly!")
)
);
console.log(myPromise);
// The invocation above will return:
Promise { <state>: "fulfilled", <value>: "I will code sweetly" }

Here’s another example:

// Create a thenable object:
const firstTest = {
then: function (fulfilled, rejected) {
rejected("Just a trial");
}
}
// Create another thenable object:
const secondTest = {
then: function (fulfilled) {
fulfilled(firstTest);
}
}
// Pass in secondTest's thenable object as an argument to the resolve() method:
Promise.resolve(secondTest);
// The invocation above will return:
Promise { <state>: "rejected", <reason>: "Just a trial" }

The snippet above passed a thenable object as an argument to the Promise.resolve() method. However, the Promise.resolve() method unwrapped the thenable object down to its non-thenable value. Therefore, the resultant promise object resolved to the "Just a trial" rejected string value.