JavaScript ES10 What's new?
Chrome v72 brings some new Es2019 features.
- 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.
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.
2. flatMap()
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() —
trim() — remove all spaces from both sides
trimStart()- remove spaces from start
trimEnd()- remove spaces from end
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
7. Comparing Symbol makes easy — Symbol. description getter
Previously we compare symbols
Now we can do the easy comparison —