creation
Promise.resolve
Returns a promise fulfilled with the given value, or — if the value is already a promise or thenable — the same/adopted promise. Handy for normalizing 'might be a promise' inputs.
Promise.resolve(value) Parameters
| Parameter | Purpose |
|---|---|
| value | Any value — plain or thenable |
| thenable adoption | If value is a thenable, Promise.resolve follows its state |
| same-promise | If value is already a native Promise, the same instance is returned |
Examples
const p = Promise.resolve(42);
p.then(v => console.log(v)); // 42 Immediately fulfilled with 42.
function loadCached(key) {
return cache.has(key)
? Promise.resolve(cache.get(key))
: fetch(key).then(r => r.json());
} Return a resolved promise to keep the API async-uniform.
const inner = new Promise(res => setTimeout(() => res('x'), 100));
const outer = Promise.resolve(inner);
console.log(outer === inner); // true (adopts, doesn't wrap) Passing a native promise returns the same instance.
Gotcha
Promise.resolve(thenable) follows the thenable — if that thenable rejects, so does yours. Cannot cancel or replace the value once created.
Related
Promise.reject
Returns a promise that is already rejected with the given reason. Useful for early-exit paths in functions that must always return a promise.
new Promise
Constructs a promise from an executor function that receives resolve and reject callbacks. Use it to adapt callback-based or event-based APIs into promises.
Promise.withResolvers
Creates a promise and exposes its resolve and reject callbacks alongside it, avoiding the need to capture them from a new Promise executor. Added in ES2024 for the 'deferred' pattern.
← All JS Promise reference · async/await vs promises vs callbacks