Introduction to ECMAScript 2019 or ES10
ECMAScript 2019 is the 10th version of the ECMAScript, also known as ES10 or ES2019. This version introduces some methods and functions which allow the developers to write less code and do more productive work.
The features introduced in ECMAScript are given below:
- String.trimStart() and String.trimEnd()
- Optional catch binding
We will discuss each of them later in this module. So let's begin.
Array.flat() is a method that is used to flatten an array. However, there are some situations where the elements of an array are also an array. These types of arrays are also known as nested arrays. Previously, we had to use the recursion to sort these types of arrays. But now, we can sort nested arrays using the
flat() method to do this.
array.flapMap() method consists of the functionality of both the ways flat and map. It functions just like a map, but it also flattens the array.
This method first maps each element using a mapping function, then flatten the nested array then results in a new array. This function can be implemented on an array and takes a callback as an argument. The callback determines how the array has to be flattened (sorted).
This method can flatten the array of depth one only because internally, a map function is called by flat function with a depth of 1.
Object.fromEntries() method was introduced by the ECMAScript 2019. In ES7, there is an
object.entries() method that converts the object key-value pairs into an array. The
Object.fromEntries() method is the reverse of the
Object.fromEntries() method is used to form the object from the given key-value pairs. This method transforms the list of key-value pairs into an object whose properties are determined by the entries.
String.trimStart() and String.trimEnd()
ES10 introduces two new methods for the string class. These two methods are used to remove the extra white space from the given string. These two methods are given below:
String.trimStart() method removes extra white space from the beginning of the string.
Strim.trimEnd() method is used to remove the extra white space from the end of the string.
Optional catch binding
Previously, whether it was necessary or not, we had to bind the exception variable to the catch clause. So most of the time, it is observed that the catch block is just redundant. But the ECMAScript 10 introduced optional catch binding that allows us to use try and catch block without error variable bindings.
Note: Catch error variable is optional in ES10.
While creating a Symbol in JS, we can add a description that can be used for debugging purposes. But accessing this description is quite tricky. To access the specified description, we have to construct the Symbol again using the
ECMAScript 2019 introduced a new read-only property known as description. This property is used to return the description of the Symbol.
In this lesson, we have learned new features introduced in ECMA Script 2019 (ES10). We will explain each in detail in upcoming articles.