promise.finally(onFinally) runs a function when a promise is settled, whether it fulfilled or rejected. It is made for cleanup, such as hiding a loading spinner. Your function gets no arguments, and its return value is ignored: the original value or error passes through. Only a throw (or a rejected promise) inside finally can change the result.
Remember
promise.finally(onFinally)
onFinally() → no arguments at all
runs after success → yes
runs after failure → yes
return value → ignored
value or reason → passes through unchanged
onFinally throws → new promise rejects with that error
Syntax
Call finally on a promise, usually after your then and catch steps, and pass one function without parameters.
Run onFinally() after the promise fulfills or rejects.
promise.then(a).catch(b).finally(c)
The classic order: success, error, then cleanup that always runs.
Added in ES2018, later than then() and catch(). It returns a new promise, so you can keep chaining.
Library declarations
JavaScript
promise.finally(onFinally) // returns a new Promise
// onFinally() is called with no arguments
Parameters
Parameter
Description
onFinally
A function called with no arguments once the promise settles. Its return value is ignored, but if it returns a promise, the chain waits for that promise first.
Return Value
Return Value
Description
Promise
A new promise with the same value or reason as the original. It rejects instead if onFinally throws or returns a rejected promise.
JavaScript Examples
Example 1 — Cleanup After Success and Failure
A spinner must disappear whether the data arrived or not. Without finally() you would repeat that line twice.
1) cleanup failed
slow cleanup done
2) final value
How It Works
A throw inside finally wins. The promise rejected with first error, but cleanupThatFails throws, so the catch sees cleanup failed. A fulfilled value would be replaced the same way.
A returned promise is awaited.finally waits about 30 ms for slowCleanup before the chain moves on, so its message prints before line 2.
The cleanup result is ignored.slowCleanup resolves with "ignored", yet the next then gets "final value", the original result.
Compatibility
Browser & Runtime Support
Promise.prototype.finally() arrived in ES2018, later than the ES2015 then() and catch().
✓ Widely available · ES2018
Promise.prototype.finally()
Supported in Chrome 63+, Firefox 58+, Safari 11.1+, Edge 18+, and Node.js 10+. Not available in Internet Explorer.
WideAll current browsers
Google ChromeChrome 63+
Supported
Mozilla FirefoxFirefox 58+
Supported
Apple SafariSafari 11.1+
Supported
Microsoft EdgeEdge 18+
Supported
Node.jsNode.js 10+
Supported
DenoRecent versions
Supported
Internet ExplorerNo support
Not supported
finally()Very good
Bottom line: Safe for every current browser and Node.js release. Very old browsers need a polyfill.
Frequently Asked Questions
It runs a function after the promise is settled, whether it fulfilled or rejected. It is meant for cleanup work such as hiding a spinner or closing a file.
No. The function is called with no arguments, so it cannot read the result. Use then() or catch() for that. The original result still passes through.
You could, but you would write the same code twice. With finally() the cleanup is written once and always runs.
Not by returning a value, because that value is ignored. Only a thrown error or a rejected promise returned from finally() changes the result.
It is part of ES2018: Chrome 63, Firefox 58, Safari 11.1, Edge 18, and Node.js 10 and newer. Internet Explorer does not support it.