Execute Cleanup Logic in a JavaScript Promise Chain with Promise.prototype.finally()


Dec 06 2018 6 mins  
The [`Promise.prototype.finally()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally) method lets you attach a callback to a JavaScript promise that is executed once that promise is settled, whether fulfilled or rejected. It is typically used to perform cleanup logic (such as hiding loading spinners, freeing used resources, …). By using `finally()`, you don't have to duplicate that cleanup logic in both the promise’s fulfillment and rejection handlers.