finally()

ES2018+

Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected).

Syntax

promise.finally(onFinally)

Parameters

onFinally Function

A function called when the Promise is settled

Return Value

Promise

A new Promise

Examples

JavaScript
let isLoading = true;
Promise.resolve('data')
  .then(data => console.log(data))
  .finally(() => {
    isLoading = false;
    console.log('로딩 완료');
  });
Output:
// 'data' '로딩 완료'

Related Methods