wiki/content/20201111095454-javascript_promises_finally.md

40 lines
590 B
Markdown
Raw Permalink Normal View History

2024-05-06 20:40:05 +00:00
---
2024-10-30 17:34:11 +00:00
date: 2020-11-11
2024-05-06 20:40:05 +00:00
id: 189b65a7-906f-41fd-91cd-57c4cc5764d2
title: JavaScript Promises Finally
---
# Introduction
Like [Exceptions](20201111094033-javascript_exceptions_finally), since
[ES2018](20201030095105-es2018) JavaScript
[Promises](20200911154351-promises) also support `.finally()`.
# Syntax
``` javascript
promise
.then((result) => {})
.catch((error) => {})
.finally(() => {});
```
## Shorthand
``` javascript
promise.finally(() => {});
```
is equal to
``` javascript
promise.then(
(result) => {
return result;
},
(error) => {
throw error;
}
);
```