Let’s jump right in and take a look at the following code snippet, which includes a custom function that checks to see whether a given variable is a function or not:
In the above example:
- We create two different variables – a function type variable and a string type variable.
- We create a custom function called isFunction, which checks to see if a JS variable is of type “function” or not. This returns TRUE or FALSE.
- We then test both of our variables and log the results to the console.
Best of all, the custom function above will even work in old browsers such as Internet Explorer 6!
Hopefully, you found this guide to be helpful!