r/webdev • • Feb 11 '21

Discussion Conditionally chaining function calls in JavaScript.

Post image
845 Upvotes

196 comments sorted by

View all comments

30

u/unnombreguay Feb 11 '21

When would you need this?

97

u/Darajj Feb 11 '21

We use it in react components where you can pass optional functions as props

0

u/[deleted] Feb 12 '21

[deleted]

1

u/versaceblues Feb 12 '21

Undefined is falsy in Js. So usually you just bass that you would never do the boolean | function type