instance

.finally()

Runs a callback after the promise settles regardless of outcome, without changing the resolved value or rejection reason. Ideal for cleanup like hiding spinners or closing connections.

promise.finally(onFinally)

Parameters

Parameter Purpose
onFinally() Called with NO arguments — you don't know success vs failure
pass-through Returned value is IGNORED; the outer promise keeps the original settlement
throws propagate If onFinally throws or returns a rejected promise, the outer chain rejects with that reason

Examples

showSpinner();
fetchData()
  .then(render)
  .catch(showError)
  .finally(() => hideSpinner());

Spinner is always hidden, whether fetchData resolved or rejected.

Promise.resolve('ok')
  .finally(() => 'ignored')
  .then(v => console.log(v)); // 'ok'

The return value of .finally does not replace the resolved value.

Promise.resolve('ok')
  .finally(() => { throw new Error('cleanup failed'); })
  .catch(e => console.log(e.message)); // 'cleanup failed'

Throwing in .finally does hijack the chain into rejection.

Gotcha

.finally receives no arguments — you can't tell success from failure inside it. Its return value is dropped unless it's a rejected promise or the callback throws.

Related

← All JS Promise reference · async/await vs promises vs callbacks