var bPromise = new Promise(function (resolve) { console.log('start'); resolve(100); }); bPromise.then(function (value) { return value * 2; }).then(function (value) { return value * 2; }).then(function (value) { console.log("2: " + value); // => 100 * 2 * 2 });
The output is as follows:
start 2: 400
The above code looks like, the function in the promise is executed only once (only one start output), even if there are multiple thens.
It does, and here's why:
every promise object that executes then is a new object! A new object is returned from the previous then.