DEV Community

Discussion on: I Built an App That Uses All 7 New Features in JavaScript ES2020

Collapse
 
verygooddog profile image
Alia

I've been waiting on nullish coalescing and BigInts for a while and I'm excited it's (hopefully) coming soon.
Also, if I recall correctly, BigInts can't interoperate with regular Numbers, did the spec change?

Collapse
 
thawkin3 profile image
Tyler Hawkins

Right?? Nullish coalescing and optional chaining have been the ones I've been most excited about.

For BigInt, you're right, you can't mix a BigInt with a normal number. So if you want to do some operation on a BitInt and a number, you need to convert one of them to the other format.

So for instance, you can't do:

const aBigInt = BigInt(100)
const aNumber = 50
const result = aBigInt + aNumber // incorrect!

But you could do:

const result = aBigInt + BigInt(aNumber)

Or:

const result = Number(aBigInt) + aNumber