Signup/Sign In

Introduction to ECMAScript 2019 or ES10

ECMAScript (ES) is a scripting language that is standardized by ECMA International in ECMA-262. The ECMAScript was created to standardize JavaScript to provide interoperability to the web pages across multiple browsers. A new version of ECMA Script is released every year with some exciting new features.

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:

  • Array.flat()
  • Array.flatMap()
  • Object.fromEntries()
  • String.trimStart() and String.trimEnd()
  • Optional catch binding
  • Symbol.description

We will discuss each of them later in this module. So let's begin.

Array.flat()

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.

Syntax

arr.flat(|depth|);

Array.flatMap()

The 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.

Syntax

arr.flatMap(callback);

Object.fromEntries()

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.entries() method.

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.

Syntax

Object.fromEntries(Iterable);

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()
  • String.trimEnd()

The String.trimStart() method removes extra white space from the beginning of the string.

Syntax

String.trimStart();

The Strim.trimEnd() method is used to remove the extra white space from the end of the string.

Syntax

String.trimEnd();

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.

Symbol.description

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 toString() method.

ECMAScript 2019 introduced a new read-only property known as description. This property is used to return the description of the Symbol.

Conclusion

In this lesson, we have learned new features introduced in ECMA Script 2019 (ES10). We will explain each in detail in upcoming articles.



About the author:
I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight