Say I have a method that takes an optional param that is a callback function. At some point in the method, if that function exists, I should call it. Is there a best practice for doing this?
I like this approach:
!!callback && callback();
But I've seen it's simplier form
callback && callback();
which feels wrong (because it's not explicitly converting
callback to a boolean).
I could of course use
if, but those seem unnecessarily verbose.
I've googled around a bit, but I'm not seeing anything concrete on this subject. Does a best practice for this scenario exist?