JavaScript Program to Check If a Variable is of Function Type

To understand this example, you should have the knowledge of the following JavaScript programming topics:


Example 1: Using instanceof Operator

Output

The variable is not of function type
The variable is of function type

In the above program, the instanceof operator is used to check the type of variable.


Example 2: Using typeof Operator

Output

The variable is not of function type
The variable is of function type

In the above program, the typeof operator is used with strict equal to === operator to check the type of variable.

The typeof operator gives the variable data type. === checks if the variable is equal in terms of value as well as the data type.


Example 3: Using Object.prototype.toString.call() Method

Output

The variable is not of function type
The variable is of function type

The Object.prototype.toString.call() method returns a string that specifies the object type.