JavaScript ES10 What's new?

Shivam Gupta
3 min readApr 8, 2019

--

Chrome v72 brings some new Es2019 features.

  1. flat()

Suppose we have nested array so how we make a plain array? we need to loop over and over or recursion or use some algorithm to do this.

Tow level nested Array

But in Es10 we can achieve this by flat map.

arr.flat() — It will recursively flat 1 level nested array.

arr.flat().flat()- flat 2 nested level for our example it will flat.

arr.flat(Infinity)- It will flat all level array when we don't know how much nesting present in the array.

Example- flat() method

2. flatMap()

Mapped array is not a flat array

we can use the flatmap method here to get a plain array.

3. Object.fromEntries()

Object.entries() method gives key value pair of an Object in Form of Array.

Object.fromEntries() provide original object back. See example —

4. trimStart() and trimEnd() —

String with begining and last spaces

trim() — remove all spaces from both sides

trimStart()- remove spaces from start

trimEnd()- remove spaces from end

trimStart() , trimEnd()

5. In try-catch: error parameter is now optional —

try {

throw new Error(‘Hey’)

} catch(err){ console.log(err)} // It was necessory parameter before ES10

Now we can ignore — (err)

try { throw new Error(‘Hey’)

} catch{ console.log(‘Hey error’)}

6. Using .toString() with function to get original source code

Improvement in toString() method

7. Comparing Symbol makes easy — Symbol. description getter

Previously we compare symbols

Comparing Symbol old way

Now we can do the easy comparison —

Symbol Comparison

--

--

Shivam Gupta
Shivam Gupta

Written by Shivam Gupta

Full Stack Engineer (Web/App) working on different JS Technologies & frameworks— Angular, Node, Typescript, Ionic, Firebase, AWS, ElK...Love to write cool stuff

No responses yet