Some of the new features are still proposal / not compatible in all browsers. So if you are playing with the code, try to use Google Chrome.
And some of them may
Private Fields
From the counterDemo class, the #counter value is private. If we try to access the #counter, then syntax error will be shown.
Big Int Multiplication
We can multiply 1234567890123456789n * 123n and obtain the correct value if we use BigInt.
Array Flat
Array.flat will convert nested array items to a flat list. By default, it will convert 1 level deep. You can use
const array = [ 1, [2 , [3 , 4 , [5 , 6 ] ]]]
array.flat(Infinity);
The output will be 1 2 3 4 5 6. if we use Infinity it will recursively convert to a flat list.
Object.fromEntries
We have use Object.entries in many cases. It will return an array from an object. Similarly, we can use the Object.fromEntries that will return the object from an array.
Top comments (10)
Oh that Array.flat() is so tasty for me!
any possible usecases?
Hm... using arr.flat().includes(something) to find into nested arrays without using recursion.
Dunno, just the first usecase jumped into my mind.
It works in chrome devtools now. I found Cannot mix BigInt and other types, use explicit conversions.
So don't omit the trailing n in each number.
What a crazy world we are living in.
I treat Javascript like a compilation target for more sane languages these days.
I don't know why but my brain thinks your banner is written as JAASCRIPT 😂
V is hidden there 😜 I have used ASCII text generator to do that 😊
Excellent Summary of what is coming in javascript. thank you
Great post!