I personally prefer
typeof callback === 'function' && callback();
The typeof
command is dodgy however and should only be used for "undefined"
and "function"
The problems with the typeof !== undefined
is that the user might pass in a value that is defined and not a function
More Related Contents:
- How to return value from an asynchronous callback function? [duplicate]
- Aren’t promises just callbacks?
- How can I pass a parameter to a setTimeout() callback?
- Pass correct “this” context to setTimeout callback?
- Pass an extra argument to a callback function
- Why does the setInterval callback execute only once?
- Callback after all asynchronous forEach callbacks are completed
- Declaring multiple variables in JavaScript
- JavaScript: What dangers are in extending Array.prototype?
- style.display=’none’ doesn’t work on option tags in chrome, but it does in firefox
- setting a variable to get return from call back function using promise
- JavaScript setTimeout() won’t wait to Execute? [duplicate]
- What is “callback hell” and how and why does RX solve it?
- What does this “(function(){});”, a function inside brackets, mean in javascript? [duplicate]
- understanding the concept of javascript callbacks with node.js, especially in loops
- JavaScript braces on new line or not? [closed]
- Set a callback function to a new window in javascript
- jQuery event delegation
- Is there a better way of writing v = (v == 0 ? 1 : 0); [closed]
- Executing async code on update of state with react-hooks
- Why “$().ready(handler)” is not recommended?
- How to pass a callback as a parameter into another function
- How to make non-blocking javascript code?
- Are there any coding standards for JavaScript? [closed]
- Dynamically loading css file using javascript with callback without jQuery
- Node.js: When to use Promises vs Callbacks
- javascript: execute a bunch of asynchronous method with one callback
- How to sync JavaScript callbacks?
- XSS attacks and style attributes
- JavaScript Callback after calling function