The Boolean Type

The Boolean type is the reference type corresponding to the Boolean values. To create a Boolean object, use the Boolean constructor and pass in either true or false:

var booleanObject = new Boolean(true);

Instances of Boolean override the valueOf() method to return a primitive value of either true or false.

The toString() method is overridden to return a string of "true" or "false".

The typeof operator returns "boolean" for the primitive but "object" for the reference.

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var booleanObject = new Boolean(true); 
        document.writeln(typeof booleanObject);//object
        document.writeln(typeof false);//boolean
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo

A Boolean object is an instance of the Boolean type. A Boolean object will return true when used with the instanceof operator, whereas a primitive value returns false:

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">

        var falseObject = new Boolean(false);
        var result = falseObject && true;
        document.writeln(result);  //true

        var falseValue = false;
        result = falseValue && true;
        document.writeln(result);  //false
        document.writeln(typeof falseObject); //object 
        document.writeln(typeof falseValue); //boolean 
        document.writeln(falseObject instanceof Boolean); //true 
        document.writeln(falseValue instanceof Boolean); //false 
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo