Consider this situation.
new Promise(function(resolve, reject) {
var x = resolve(2);
});
What value will x
be?
I tried to print it and it showed me undefined
. It is intuitive, but is it always so? Is it in docs?
Second question
new Promise(function(resolve, reject) {
resolve(2);
return 5;
});
What should we return from the function that we put into a promise? Is this value ignored?
The return value of the promise constructor is ignored.
The resolve
function also returns undefined.
This was first specified in the promise constructor spec and later in the ES2015 (ES6) language specification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With