JS: what’s a use-case of Promise.resolve()

I am looking at https://www.promisejs.org/patterns/ and it mentions it can be used if you need a value in the form of a promise like:

var value = 10;
var promiseForValue = Promise.resolve(value);

What would be the use of a value in promise form though since it would run synchronously anyway?

If I had:

var value = 10;
var promiseForValue = Promise.resolve(value);

promiseForValue.then(resp => {

wouldn't just using value without it being a Promise achieve the same thing:

 var value = 10;

Read more here: https://stackoverflow.com/questions/65712269/js-whats-a-use-case-of-promise-resolve

Content Attribution

This content was originally published by RicardoAlvveroa at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: