(javascript) chaining promises automatically resolve?

I was reading an online tutorials which says that the value returned by .then is a promise, and when the value is returned, that promise becomes resolved, so the next handler runs with the value. lets say we have this piece of code:

new Promise(function(resolve, reject) {

  setTimeout(() => resolve(1), 1000); // (*)

}).then(function(result) { // (**)

  console.log('first resolve'); // 1
  return result * 2;  //  <------------------comment out later

}).then(function(result) { // (***)

  console.log('second resolve'); // 2
  return result * 2;

})

so my question is, how the second promise get settled? does get resolved automatically? because if I comment out the return line, I can still get the 'second resolve' printed on the screen, but according to the tutorial: when the value is returned, that promise becomes resolved, so I comment out the return statement, how come the promise still become resolved?

728x90

0 Answers (javascript) chaining promises automatically resolve?