7

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?

1 Answers1

7

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.

Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504