Javascript boolean object example

Javascript boolean object:

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

How to create javascript boolean object:

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


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


<!DOCTYPE html>
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);

Try it:

JS Bin on

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 value.
valueOf() It returns the primitive value of the Boolean object.


Comments are closed.