JavaScript Promise.resolve(): Create Resolved Promises

Learn Promise.resolve() in JavaScript with resolved values, existing promises, thenables, async functions, and Promise.reject comparison.

Published

Updated

Read time 3 min read

Reviewed byDeepak Prasad

JavaScript Promise.resolve(): Create Resolved Promises

Promise.resolve() returns a Promise that is resolved with a given value. It is commonly used when a function should return a promise even though the value is already available, when normalizing sync and async code, or when adopting another promise or thenable.

The method is simple, but the behavior matters: if you pass a normal value, the returned promise fulfills with that value. If you pass a promise, Promise.resolve() follows that promise's final state.

Environment: Node.js v20.18.2. After each runnable snippet, the following paragraph states the expected console output (order and values).


JavaScript Promise.resolve Syntax

javascript
Promise.resolve(value)
Output

value can be a plain value, an object, an existing promise, or a thenable object.


Method 1: Resolve a Plain Value

Use Promise.resolve() to wrap a value in a fulfilled promise.

javascript
Promise.resolve("ready")
  .then((value) => {
    console.log("resolve-value:", value);
  });
Output

You should see one line logging resolve-value: ready.

This is useful when an API should always return a promise, even when the data is already available.


Method 2: Resolve an Existing Promise

If the value is already a promise, Promise.resolve() follows that promise.

javascript
Promise.resolve(Promise.resolve(7))
  .then((value) => {
    console.log("resolve-promise:", value);
  });
Output

You should see one line logging resolve-promise: 7.

The result is not a nested promise value. JavaScript unwraps the promise and passes the final fulfilled value to .then().


Method 3: Normalize Sync and Async Results

Promise.resolve() is useful when a function may return either a direct value or a promise, but the caller wants one consistent promise-based flow.

javascript
function maybeCached(useCache) {
  if (useCache) {
    return "cached user";
  }

  return Promise.resolve("loaded user");
}

Promise.resolve(maybeCached(true))
  .then((value) => console.log(value));
Output

You should see one line logging cached user.

This pattern is common in libraries that accept callbacks, plugins, or loaders that may be synchronous or asynchronous.


Method 4: Use Promise.resolve in Async Functions

An async function automatically wraps returned values in a promise, so you usually do not need Promise.resolve() inside it.

javascript
async function getStatus() {
  return "ready";
}

getStatus().then((status) => console.log(status));
Output

You should see one line logging ready.

Use a direct return in async functions unless you specifically need to adopt a value before returning it.


Promise.resolve vs Promise.reject

Promise.resolve() creates or adopts a fulfilled promise. Promise.reject() creates a rejected promise.

javascript
Promise.resolve("ok").then((value) => console.log(value));
Promise.reject(new Error("not ok")).catch((error) => console.log(error.message));
Output

You should see 2 lines, in order: ok, not ok.

Use Promise.resolve() for successful values and Promise.reject() for controlled failures in promise-returning functions.


Common Questions About Promise.resolve

What does Promise.resolve return?

It returns a promise. The promise fulfills with the value you pass, or follows the state of the promise or thenable you pass.

Do I need Promise.resolve inside async functions?

Usually no. An async function already returns a promise and automatically wraps non-promise return values.

Is Promise.resolve synchronous?

The promise object is created immediately, but .then() callbacks run asynchronously in the microtask queue after the current call stack finishes.


Summary

Promise.resolve() is a JavaScript helper for creating a fulfilled promise from a value and for normalizing values that may or may not already be promises. It is useful in promise-returning APIs, cache paths, plugin systems, and tests. In async functions, a plain return is usually enough because JavaScript wraps the returned value in a promise automatically.


Official Documentation

Olorunfemi Akinlua

Boasting over five years of experience in JavaScript, specializing in technical content writing and UX design. With a keen focus on programming languages, he crafts compelling content and designs …