mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-23 03:56:23 +00:00
39 lines
573 B
Markdown
39 lines
573 B
Markdown
|
---
|
||
|
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;
|
||
|
}
|
||
|
);
|
||
|
```
|