DEV Community

Discussion on: 9 Extremely Powerful JavaScript Hacks

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!