The Promise is an object that represents either completion or failure of a user task. A promise in JavaScript can be in three states pending, fulfilled or rejected.
The main advantage of using a Promise in JavaScript is that a user can assign callback functions to the promises in case of a rejection or fulfillment of Promise. As the name suggests a promise is either kept or broken. So, a promise is either completed(kept) or rejected(broken).
Promise resolve() method:
Promise.resolve() method in JS returns a Promise object that is resolved with a given value. Any of the three things can happend:
- If the value is a promise then promise is returned.
- If the value has a “then” attached to the promise, then the returned promise will follow that “then” to till the final state.
- The promise fulfilled with its value will be returned.
Syntax:
Promise.resolve(value);
Parameters:
Value to be resolved by this Promise.
Return Value:
Either the promise of the promise fulfilled with its value is returned.
Examples:
<script> var promise = Promise.resolve(17468); promise.then(function(val) { console.log(val); }); //Output: 17468 </script> |
Output:
17468
Resolving an array:
<script> const promise = new Promise((resolve, reject) => { setTimeout(() => { resolve([89, 45, 323]); }, 5000); }); promise.then(values => { console.log(values[1]); }); </script> |
Output:
45

Resolving another Promise:
<script> const promise = Promise.resolve(3126); const promise1 = new Promise((resolve, reject) => { setTimeout(() => { promise.then(val => console.log(val)); }, 5000); }); promise1.then(vals => { console.log(vals); }); </script> |
Output:
3126

Recommended Posts:
- JavaScript | Promise.all() Method
- JavaScript | Promise.allSettled() Method
- How to wrap setTimeout() method in a promise ?
- Node.js | fs.promise.readdir() Method
- jQuery Deferred .promise() method
- Node.js | dns.resolve() Method
- Node.js | dnsPromises.resolve() Method
- Node.js | path.resolve() Method
- JQuery deferred.resolve() method
- How to wait for a promise to finish before returning the variable of a function?
- How to convert an existing callback to a promise in Node.js ?
- Node.js | Promise Chaining
- How to resolve unhandled exceptions in Node.js ?
- Node | URL.resolve(from,to) API
- How to resolve 'node' is not recognized as an internal or external command error after installing Node.js ?
- JavaScript Course | Understanding Code Structure in JavaScript
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


