JavaScript: What’s new in ECMAScript 2019 (ES2019)/ES10?

Selvaganesh
3 min readFeb 8, 2019

--

Chrome Version 72 rolled out new exciting ES10 features for developer to use in browser.

1. Array.Flat()

The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

2.Array.flatMap()

The flatMap() method first maps each element using a mapping function, then flattens the result into a new array. It is identical to a map followed by a flat of depth 1, but flatMap is often quite useful, as merging both into one method is slightly more efficient.

3.Object.fromEntries()

The Object.fromEntries() method transforms a list of key-value pairs into an object.

Note: Object.fromEntries only accept iterable (i.e) Object.fromEntries(iterable)

It will accept only Map or Array

Example 1

Example 2

4.String.trimStart() & String.trimEnd()

The trimStart() method removes whitespace from the beginning of a string.

The trimEnd() method removes whitespace from the end of a string.

You can think why another new method already there are two method trimRight()and trimLeft() but it will be alias of above new methods

5.Optional Catch Binding

Allow developers to use try/catch without creating an unused binding.
You are free to go ahead make use of catch block without a param

Earlier it is mandatory to use param in catch block

6.Function.toString()

The toString() method returns a string representing the source code of the function.Earlier white spaces,new lines and comments will be removed when you do now they are retained with original source code

7.Symbol.description

The read-only description property is a string returning the optional description of Symbol objects.

8.Well Formed JSON.Stringify()

To prevent JSON.stringify from returning ill-formed Unicode strings.

9.Array.Sort Stability

Users with same rating retain their sorting order

Previously, V8 used an unstable QuickSort for arrays with more than 10 elements. As of V8 v7.0 / Chrome 70, V8 uses the stable TimSort algorithm. 🎉

The only major engine JavaScript engine that still has an unstable Array#sort implementation is Chakra, which uses QuickSort for arrays with more than 512 elements (and stable insertion sort for anything else).

For more info read this article

10.JSON ⊂ ECMAScript (JSON Superset)

Extend ECMA-262 syntax into a superset of JSON.

JSON syntax is defined by ECMA-404 and permanently fixed by RFC 7159, but the DoubleStringCharacter and SingleStringCharacter productions of ECMA-262 can be extended to allow unescaped U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR characters.

For more info read this proposal

If you like this article share and clap 👏 👏. Thanks!

--

--

Responses (7)