304 Followers
·
Follow

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

Image for post
Image for post

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.

Image for post
Image for post

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

Image for post
Image for post

Example 2

Image for post
Image for post

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

Image for post
Image for post

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

Image for post
Image for post

Earlier it is mandatory to use param in catch block

Image for post
Image for post

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

Image for post
Image for post

7.Symbol.description

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

Image for post
Image for post

8.Well Formed JSON.Stringify()

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

Image for post
Image for post

9.Array.Sort Stability

Users with same rating retain their sorting order

Image for post
Image for post

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

Image for post
Image for post

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

Written by

I try to learn and help others by sharing what I find | https://www.youtube.com/user/ganeshrsg | https://github.com/ganny26

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store