r/node • • Nov 10 '20

Conditionally call a function with optional chaining.

Post image
345 Upvotes

126 comments sorted by

View all comments

1

u/[deleted] Nov 10 '20

I often used something like this:

const xs = //something from an api const ys = mapFun ? xs.map(x => mapFun(x)) : xs;

where mapFun is passed as an argument but it maybe not passed at all