Promise.prototype.finally()

Registers a callback that runs when the promise settles, regardless of outcome.

Since ES2018 Spec ↗

Syntax

promise.finally(onFinally)

Returns

Promise — A promise that settles with the original outcome (unless `onFinally` throws or rejects).

Examples

Promise.resolve("ok")
  .finally(() => console.log("cleanup"))
  .then(v => console.log(v));
Output
cleanup
ok
Promise.reject(new Error("fail"))
  .finally(() => console.log("always"))
  .catch(e => console.log(e.message));
Output
always
fail

Notes

- `onFinally` receives no arguments and cannot inspect the outcome. - It passes through the original value or rejection unchanged. - Ideal for cleanup such as hiding a loading spinner.

Browser & runtime support

EnvironmentSince version
chrome 63
firefox 58
safari 11.1
edge 18
node 10.0

See also