Promise Chains with the finally() Method
Discover how the finally() method is used in promise chains.
We'll cover the following...
Using finally()
in promise chains
The finally()
method behaves differently than both then()
and catch()
in that it copies the state and value of the previous promise into its returned promise. That means if the original promise is fulfilled with a value, then finally()
returns a promise that is fulfilled with the same value. For example, we have the following:
Press + to interact
const promise = Promise.resolve(11);promise.finally(() => {console.log("Finally called.");}).then(value => {console.log(value); // 11});
Here, the settlement handler can’t receive the fulfilled value from promise, so that value is copied to a new promise that is returned from the method call. The new ...
Access this course and 1400+ top-rated courses and projects.