Javascript Boolean Object

A JavaScript Boolean object can represent two values “true” or “false”.

How to create a Javascript boolean object:

1. By using boolean literals.
2. By using Boolean() constructor.

Syntax:

Var b1 = true;
var b2 = new Boolean(value);

Example:

<!DOCTYPE html>
<html>
<body>
<script>
var boolean1=new Boolean(true);
var boolean2=new Boolean(false);
var boolean3=true;
document.write("Boolean1: "+boolean1+ "</br>");
document.write("Boolean2: "+boolean2+ "</br>");
document.write("Boolean3: "+boolean3);
</script>
</body>
</html>

Try it:

JS Bin on jsbin.com

JavaScript Boolean Object Properties

Property Description
constructor It returns a reference to the Boolean function that created the object.
prototype It allows us to add properties and methods to an object.

 

JavaScript Boolean Object Methods

Method Description
toSource() It returns a string containing the source of the Boolean object.
toString() It returns a string of object values.
valueOf() It returns the primitive value of the Boolean object.