Return Promises in Promise Chains
Learn how to return a promise from a settlement handler using then() and catch().
We'll cover the following...
Returning promises in promise chains
Returning primitive values from promise handlers allows the passing of data between promises, but what if we return an object? If the object is a promise, then there’s an extra step that’s taken to determine how to proceed. Consider the following example:
Press + to interact
const promise1 = Promise.resolve(11);const promise2 = Promise.resolve(22);promise1.then(value => {console.log(value); // 11return promise2;}).then(value => {console.log(value); // 22});
In this code, promise1
resolves to 11
. The fulfillment handler for promise1
returns ...
Access this course and 1400+ top-rated courses and projects.