Skip to content

Files

Latest commit

 

History

History
23 lines (17 loc) · 529 Bytes

no-return-in-finally.md

File metadata and controls

23 lines (17 loc) · 529 Bytes

Pattern: return statement in Promise.finally()

Issue: -

Description

Using a return statement inside a finally() callback is ineffective since the returned value will not be consumed. The finally() block should only be used for cleanup code that needs to run regardless of the promise outcome.

Examples

Example of incorrect code:

myPromise.finally(function (val) {
  return val;
});

Example of correct code:

Promise.resolve(1).finally(() => {
  console.log(2);
});