r/node • • Nov 10 '20

Conditionally call a function with optional chaining.

Post image
345 Upvotes

126 comments sorted by

View all comments

Show parent comments

17

u/[deleted] Nov 10 '20

[removed] — view removed comment

3

u/VolperCoding Nov 10 '20

Languages like C++ don't have optionals because they're low level-ish. Typescript is a superset of Javascript so if course it has to feature hull and undefined

3

u/[deleted] Nov 10 '20

Scala and every other FP language does too. Optionals are just an abstraction on top of null pointers, you can reason about them and handle them in a more elegant way. There's nothing 'basic' about this. Java has them in the more recent versions too.

Rather than null-pointer checks everywhere, you have some really nice syntax to deal with it, and it's a lot more transparent in the code.

1

u/Qildain Nov 10 '20

The billion dollar mistake... as a (primarily) JVM language dev, I abhor null checks. I'm glad they pulled it into vanilla.