Return Value of Promise Enable / Reject Functions

Consider this situation.

new Promise(function(resolve, reject) { var x = resolve(2); }); 

What is the value of x ? I tried to print it and it showed me undefined . This is intuitive, but is it always so? Is it in the docs?

Second question

 new Promise(function(resolve, reject) { resolve(2); return 5; }); 

What should we return from the function that we put in the promise? Is this value ignored?

+5
javascript promise return-value
source share
1 answer

The return value of the promise constructor is ignored .

The resolve function also returns undefined .

This was first stated in the promise constructor specification, and then in the language specification .

+4
source share

All Articles