How to Check if a Variable is of Function Type
Read this JavaScript tutorial and learn several fast and useful methods that are invoked for checking whether the variable is of function type or not.
There are several methods in JavaScript that can check whether a variable is of function type. Let’s discuss each of them and find the fastest solution to the question.
The typeof Operator
You can use the typeof operator to check the variable. It returns a string which indicates the type of the unevaluated operand.
Javascript typeof method
The instanceof Operator
Another method can be the instanceof operator which checks the type of an object at run time. It returns a corresponding boolean value, for example, either true or false to indicate if the object is of a particular type or not:
Javascript instanceof method
The typeof operator appears to be the fastest in Chrome, but in Firefox the instanceof operator is the winner.