var p = new Promise(function(resolve, reject) {
setTimeout(function() {
resolve("OK");
}, 2000);
});
p.then().then(function(data) {
console.log(data);
});
I don’t understand what happens after the first "then" is called. When the first "then" is called it returns undefined, which in turn resolves Promise created for this "then" with a value "undefined". Yet, for some reason, when the second "then" is called it is passed "OK" as "data" and subsequently logs it. Where did the "data" come from ?
2
Answers
This "forwarding" of the value is intended behaviour. Mozilla contributors write: