.resolve()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Jul 27, 2021Updated Aug 29, 2023
Contribute to Docs

Returns a new Promise object that turns into the value that was passed to the method.

Syntax

Promise.resolve(value);

The value can be most data types, including:

  • numbers
  • strings
  • objects (even other Promise objects)

Example #1

With non-Promise values:

const promiseA = Promise.resolve(1);
const promiseB = Promise.resolve({
status: 'Success',
message: 'The Promise was fulfilled!',
});
console.log(promiseA);
console.log(promiseB);

Example #2

With Promise values:

const innerPromise = new Promise((resolve, reject) => {
if (2 + 2 === 4) {
resolve('Success!');
} else {
reject('Something went wrong..');
}
});
const outerPromise = Promise.resolve(innerPromise);
outerPromise
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
// Output: Success!

Codebyte Example

The following example shows a promise settled after the 1st resolve callback and ignores the rest for execution.

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn JavaScript on Codecademy