Promise finally()
The finally() method of Promise instances schedules a function to be called when the promise is settled (either fulfilled or rejected). It immediately returns another Promise object, allowing you to chain calls to other promise methods.
Like the finally block, this method is usually intended for cleanup actions, regardless of the promise's outcome. It lets you avoid duplicating code in both the promise's then() and catch() handlers.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 63 | 18 | 58 | 11.1 | 63 | 11.3 | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
JAVASCRIPT
showLoading();
fetch('/api/data')
.then(response => response.json())
.then(data => displayData(data))
.catch(error => showError(error))
.finally(() => hideLoading()); Live demo
button. doublesubmitprevention
redegreeenabledization.. with ProcessingStart time to button disabledization, end time to finally.
PreviewFullscreen
Use cases
-
Resetting transient UI
Hide spinners, re-enable buttons, or clear temporary state once an async action finishes.
-
Releasing resources
Close connections, remove locks, or stop timers in one shared place instead of duplicating cleanup logic.
Cautions
- finally does not receive the resolved value or rejection reason directly, so use then/catch for result-specific behavior.
- Cleanup code inside finally should stay safe and predictable, because throwing there changes the resulting Promise state.
Accessibility
- If loading UI is removed in finally, make sure the completion state is still announced or visible afterward.