Promise.resolve
Returns a Promise object that is resolved with a given value
Syntax
Promise.resolve(value)Parameters
| Parameter | Type | Description |
|---|---|---|
| value | T | PromiseLike<T> | The value to resolve the promise with |
Return Value
A Promise that is resolved with the given value
Examples
const p = Promise.resolve(42);
p.then(val => console.log(val)); // 42async function fetchWithFallback(url: string, fallback: string) {
try {
const res = await fetch(url);
return await res.text();
} catch {
return Promise.resolve(fallback);
}
}const values = [1, Promise.resolve(2), 3];
Promise.all(values).then(console.log); // [1, 2, 3]Understanding Promise.resolve
The Promise.resolve method in JavaScript returns a Promise object that is resolved with a given value. It belongs to the Promise object and is one of the most widely used methods for working with promise values in modern JavaScript and TypeScript applications.
The method signature is Promise.resolve(value). It accepts 1 parameter: value. When called, it returns a promise that is resolved with the given value. Understanding when and how to use resolve() helps you write more expressive, readable code.
Common use cases for Promise.resolve include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like promise-reject, promise-all, promise-then, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Promise.resolve is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Promise.rejectReturns a Promise object that is rejected with a given reason
Promise.allTakes an iterable of promises and returns a single promise that resolves when all of the input promises have resolved, or rejects when any input promise rejects
Promise.prototype.thenAttaches callbacks for the resolution and/or rejection of the Promise, and returns a new Promise
More Promise Methods
Other methods in the Promise object
Related Tools
More Promise Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.