You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes you may need to avoid duplicate code in the then() and catch() methods.
438
+
439
+
```js
440
+
myPromise
441
+
.then(result=> {
442
+
// process the result and then clean up the resources
443
+
})
444
+
.catch(error=> {
445
+
// handle the error and then clean up the resources
446
+
});
447
+
```
448
+
449
+
The `finally()` method is useful if you want to do some processing or resource cleanup once the promise is settled(i.e either fulfilled or rejected).
450
+
451
+
Let's take a below example to hide the loading spinner after the data is fetched and processed.
452
+
453
+
```js
454
+
let isLoading =true;
455
+
fetch('http://somesite.com/users')
456
+
.then(data=>data.json())
457
+
.catch(err=>console.error(err))
458
+
.finally(() => {
459
+
isLoading =false;
460
+
console.log('Finished loading!!');
461
+
})
462
+
```
463
+
464
+
## ES2019 Or ES10
465
+
396
466
### Array flat and flatMap
397
467
398
468
The `flat()` method is used to 'flattens' the nested arrays into the top-level array. The functionality of this method is similar to Lodash's `_.flattenDepth()` function.
@@ -454,10 +524,6 @@ Reflection is the ability of a code to inspect and manipulate variables, propert
@@ -504,7 +570,7 @@ Reflection is the ability of a code to inspect and manipulate variables, propert
504
570
505
571
**Note:** As shown in the above code, If you still try to access the variable directly from the object then you will receive syntax error.
506
572
507
-
## ES2019 Or ES10
573
+
## ES2020 Or ES11
508
574
509
575
ES2020 is the current newer version of ECMAScript corresponding to the year 2020. This is the eleventh edition of the ECMAScript Language Specification. Even though this release doesn't bring as many features as ES6, it included some really useful features.
0 commit comments