JavaScript In ES6 JavaScript, why is the promise returned by the fulfillment handler of then() not the same as the promise returned by then()? javascript promise returned is ignored,javascript promise returned,js promise

I have some squares sliding down the page, in a chained promise fashion: https://jsfiddle.net/u4x0qwfo/3

The code is:

new Promise(function(resolve, reject) {
  $("#shape").css({
    top: 100
  });
  setTimeout(function() {
    resolve();
  }, 1000);
}).then(function() {
  return new Promise(function(resolve, reject) {
    $("#shape2").css({
      top: 100
    });
    setTimeout(function() {
      resolve();
    }, 1000);
  });
}).then(function() {
  return new Promise(function(resolve, reject) {
    $("#shape3").css({
      top: 100
    });
    setTimeout(function() {
      resolve();
    }, 1000);
  });
}).then(function() {
  return new Promise(function(resolve, reject) {
    $("#shape4").css({
      top: 100
    });
    setTimeout(function() {
      resolve();
    }, 1000);
  });
});

(the code doesn't run as well inside of a snippet here: here the first square has already slide down initially).

So to see what promise is returned by the fulfillment handler, and what promise is returned by .then(), I have https://jsfiddle.net/u4x0qwfo/10/

The code is:

let foobar;

let lala = new Promise(function(resolve, reject) {
  $("#shape").css({
    // ...
}).then(function() {
  foobar =  new Promise(function(resolve, reject) {
    // ...
  return foobar;
});

lala.then(function() {
  console.log("checking:", lala, foobar, lala === foobar);
  return new Promise(function(resolve, reject) {

In the debug console, we can see that the promises are different. But why do they have to be different?

Actually inside the docs of .then() return value, it is said that:

[if .then()] returns another pending promise object, the resolution/rejection of the promise returned by then will be subsequent to the resolution/rejection of the promise returned by the handler. Also, the value of the promise returned by then will be the same as the value of the promise returned by the handler.

It suggests that the two promises are different (the one returned by the fulfillment handler and the one returned by .then()). (I can't find the description in the ES6 specs). The question is why? Can't they be the same promise?

The second part says:

Also, the value of the promise returned by then will be the same as the value of the promise returned by the handler.

I thought initially it meant "the promise returned by then will be the same the promise returned by the handler", but only to find out it actually meant: "the resolved value of the promise returned by then will be the same as the resolved value of the promise returned by the handler". (is this the proper way to describe it?).

Inside of Google Chrome, both promises will show the same resolved value of 123456: https://jsfiddle.net/u4x0qwfo/11/

Answer:1

I have many dinamic tables, each one creates a dinamic master checkbox inside an input and several checkboxes inside td's (each one has a different ID). The idea is once I check or uncheck the master ...

I have many dinamic tables, each one creates a dinamic master checkbox inside an input and several checkboxes inside td's (each one has a different ID). The idea is once I check or uncheck the master ...

  1. check all checkboxes inside div jquery
  2. check all checkboxes inside a div

I'm having a bit of a trouble here. I'm using RequireJS to load my modules and dependencies. I am trying to avoid polluting the global namespace, so I am using the following configuration as a ...

I'm having a bit of a trouble here. I'm using RequireJS to load my modules and dependencies. I am trying to avoid polluting the global namespace, so I am using the following configuration as a ...

I'm currently trying to display number series (for 2, 3, 4, 5, 6 and 7) in JavaScript. I was looking for the smallest number (x), which results in modulo = 1, if divided by 2, 3, 4, 5 and 6. If the ...

I'm currently trying to display number series (for 2, 3, 4, 5, 6 and 7) in JavaScript. I was looking for the smallest number (x), which results in modulo = 1, if divided by 2, 3, 4, 5 and 6. If the ...

  1. display prime number series in python

I am working on a search function for a parent child structure with locations (city,suburb,street). I want to search for a street name and get the results but keeping the structure. The array ...

I am working on a search function for a parent child structure with locations (city,suburb,street). I want to search for a street name and get the results but keeping the structure. The array ...

  1. filter search multiple values excel
  2. filter search multiple values
  3. filter search multiple excel
  4. filter search multiple pivot
  5. search filter multiple
  6. search filter multiple php
  7. excel filter search multiple words
  8. django-filter search multiple fields
  9. angularjs filter search multiple fields
  10. angular filter search multiple fields
  11. excel filter search multiple criteria
  12. excel filter search multiple entries
  13. excel filter search multiple items
  14. excel filter search multiple columns
  15. angularjs search filter multiple parameters
  16. ldap search filter multiple ou
  17. angular search filter multiple parameters
  18. ldap search filter multiple groups
  19. ldap search filter multiple attributes
  20. ldap search filter multiple cn