If we have:
(cb)=>{ if (cb!=null) cb()}
Is there are shorter way to check if cb is not null and call it? This will be running on Node.
Now in 2021 : Optional chaining
cb?.()
If cb is null - cb is not invoked.
if cb is a func, cb is invoked.
Note: if cb is a not function or not a non null/undefined value, (eg 23 or false) then this will throw a TypeError.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With