DEV Community

Discussion on: 9 Extremely Powerful JavaScript Hacks

Collapse
 
weeb profile image
Patrik Kiss • Edited

available && addToCart()

Mindblow

Collapse
 
razgandeanu profile image
Klaus

Felt the same way when I found out about it.

Collapse
 
benbot profile image
Benjamin Botwin

You can chain it together many times AND you can do nicer looking deep undefined checks

‘niceobj && niceobj.maybeUndefined && niceObj.maybeUndefined.functionOrValue’

Way cleaner than if statements, but not as clean as typescripts “?.” operator

Sorry for the poor formatting. On mobile.

Collapse
 
benbot profile image
Benjamin Botwin

Oh I just found out the “?.” operator might be coming to JS too and it’s already in Babel.

I highly encourage you to take a look!

dev.to/akirautio/optional-chaining...

Thread Thread
 
razgandeanu profile image
Klaus

Interesting.
Thank you for letting us know.

Thread Thread
 
mburszley profile image
Maximilian Burszley • Edited

It's not "might"; it's in stage 4 and will be added in ES2020.

Thread Thread
 
benbot profile image
Benjamin Botwin

Even better!

Collapse
 
metalmikester profile image
Michel Renaud

It's a good thing I read this article because if I had ever came across this I would have wondered what it was.