JavaScript Promise.prototype.finally() Method
The finally() method runs a function when a promise settles, whether it fulfilled or rejected, which is useful for clean-up such as hiding a loading indicator.
Description
The finally() method schedules a function to run when the promise settles, regardless of the outcome. The callback receives no arguments, and the value or error passes through it unchanged to the next step in the chain. It's the promise version of a finally block.
Unlike then(), its callback can't change the value passing through, unless it throws an error or returns a rejected promise, which replaces the result with that rejection. That makes it safe for clean-up that shouldn't interfere with the outcome, such as re-enabling a button, closing a connection or stopping a spinner.
In async functions, a finally block in a try statement does the same job, and runs whether the awaited operation succeeds or fails.
Syntax
promise.finally(onFinally)Parameters
- onFinallyA function, called with no arguments, when the promise settles either way.
Return Value
A new promise that settles the same way as the original.
Example
Browser Support
The following information will show you the current browser support for the Promise.prototype.finally() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





