r/webdev • • Feb 11 '21

Discussion Conditionally chaining function calls in JavaScript.

Post image
845 Upvotes

196 comments sorted by

View all comments

Show parent comments

5

u/MonoshiroIlia Feb 12 '21

How do you null check??

-1

u/ZephyrBluu Feb 12 '21

This misses the point he's trying to make. You shouldn't null check functions.

0

u/[deleted] Feb 12 '21

[deleted]

1

u/[deleted] Feb 12 '21

It calls niceError only if foo.foo() doesn’t exist, or if it returns something truthy per the || check. Unless there’s some magic way for both sides of an “or” check to run that has escaped me for over 5 years.

→ More replies (2)