The Promise.resolve(value) method

The resolve() method of the Promise object takes a value and returns a Promise object that resolves the passed value. The resolve() method is basically used to convert a value to a Promise object. It is useful when you find yourself with a value that may or may not be a Promise, but you want to use it as a Promise. For example, jQuery promises have different interfaces from ES6 promises. Therefore, you can use the resolve() method to convert jQuery promises into ES6 promises.

Here is an example that demonstrates how to use the resolve() method:

const p1 = Promise.resolve(4);p1.then(function(value){  console.log(value);}); //passed a promise objectPromise.resolve(p1).then(function(value){  console.log(value); ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.