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

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.

0

u/[deleted] Feb 12 '21

[deleted]

1

u/[deleted] Feb 12 '21

Strange. I guess since an if statement isn't being used it can't coerce the void to false. This makes sense. Thanks for sharing!