typeof variable == “boolean” Check if type is boolean – Code Example

Total
0
Shares

In order to check if type of variable is boolean you can use typeof variable == "boolean". If it is object then you may use toString.call(obj) === '[object Boolean]'.

Code Example

This is a universal function which can check the boolean as well as Boolean objects created using new Boolean()

isBoolean = function(obj) {
   return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
};