DEV Community

Cover image for What’s new in Javascript?

What’s new in Javascript?

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

img
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

img

We can multiply 1234567890123456789n * 123n and obtain the correct value if we use BigInt.

Array Flat

img
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

img

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)

Collapse
 
genta profile image
Fabio Russo

Oh that Array.flat() is so tasty for me!

Collapse
 
ayudhkrgupta14 profile image
Ayudh Kumar Gupta

any possible usecases?

Collapse
 
genta profile image
Fabio Russo

Hm... using arr.flat().includes(something) to find into nested arrays without using recursion.
Dunno, just the first usecase jumped into my mind.

Collapse
 
qcgm1978 profile image
Youth

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.

1234567890123456789n * 123n
Collapse
 
rohovdmytro profile image
Rohov Dmytro • Edited

Private Fields

What a crazy world we are living in.

Collapse
 
jillesvangurp profile image
Jilles van Gurp

I treat Javascript like a compilation target for more sane languages these days.

Collapse
 
larsklopstra profile image
Lars Klopstra ⚑

I don't know why but my brain thinks your banner is written as JAASCRIPT πŸ˜‚

Collapse
 
pjijin profile image
Jijin P πŸ‘¨β€πŸ’»πŸ¦„ • Edited

V is hidden there 😜 I have used ASCII text generator to do that 😊

Collapse
 
c0d3rm0nk3y profile image
Peter

Excellent Summary of what is coming in javascript. thank you

Collapse
 
tojacob profile image
Jacob Samuel G.

Great post!