We can use the isFunction
method to check whether a variable is a function or not.
jQuery.isFunction( value )
value
- This variable to be checked is passed as an argument to this method.
This method returns True
if the argument is a function. Otherwise, it returns False
.
The code written below demonstrates how we use the isFunction
method:
Line 6: We include the jQuery
file.
Lines 9–10: We create an object obj
and use the isFunction
method to check if obj
is a function. The isFunction
method returns False
, because obj
is not a function.
Lines 13–14: We create a variable val
with a value of 10
and use the isFunction
method to check if val
is a function. The isFunction
method returns False
, because the val
is not a function.
Lines 16–19: We create a function with the name hi
and use the isFunction
method to check if hi
is a function. The isFunction
method returns True
, because hi
is a function.
Free Resources