.resolve()
Anonymous contributor
Anonymous contributor2 total contributions
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.
All contributors
- Anonymous contributorAnonymous contributor2 total contributions
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- BrandonDusch580 total contributions
- Anonymous contributor
- christian.dinh
- Anonymous contributor
- BrandonDusch
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.