" In order for our chain to work properly, we had to return
the promise secondPromiseFunction(firstResolveVal)
. This ensured that the return value of the first .then()
was our second promise rather than the default return of a new promise with the same settled value as the initial."
Still, I can’t understand why do we have to return the second promise. What could go wrong if we don’t? In the exercise I wrote:
checkInventory(order)
.then(processPayment)
.then(shipOrder)
.then((successMessage) => {
console.log(successMessage);
})
.catch((errorMessage) => {
console.log(errorMessage);
});
instead of the correct answer:
checkInventory(order)
.then((resolvedValueArray) => {
return processPayment(resolvedValueArray);
})
.then((resolvedValueArray) => {
return shipOrder(resolvedValueArray);
})
.then((successMessage) => {
console.log(successMessage);
})
.catch((errorMessage) => {
console.log(errorMessage);
});
They worked the same.