0

This will log 5 and 1:

console.log(5)
    var promise1 = new Promise((resolve,reject)=>{resolve(1)});
    promise1.then(info=>{console.log(info)});

This will log 5 only:

console.log(5)
    var promise1 = new Promise((resolve,reject)=>{return 1});
    promise1.then(info=>{console.log(info)});

Why doesn't the first case log 1? I thought returning a value to the promise was same as returning value to it?

user3586940
  • 865
  • 1
  • 10
  • 18
  • 5
    Because `return` does no resolve promises. If promises would be resolved with the return value, they could not be resolved asynchronously. – Bergi Jul 10 '20 at 21:03
  • You might be [confusing this with the behavior of `then`](https://stackoverflow.com/q/31324110/1048572) – Bergi Jul 10 '20 at 21:09
  • @Bergi yup, that's why i was confused thanks :) – user3586940 Jul 10 '20 at 21:10

0 Answers0