Home >>Javascript Tutorial >JavaScript Boolean

JavaScript Boolean

JavaScript Boolean

Boolean in JavaScript is an object that represents the value of an object in two states whether true or false. A JavaScript Boolean object can be created by using Boolean() constructor as illustrated here:

Boolean b=new Boolean(value);

Note : Please note that the default value of JavaScript Boolean object is known to be false.

Here is one of the example of JavaScript Boolean:

<script>  
document.write(5<20);//true  
document.write(20<5);//false  
</script>  

Boolean properties in JavaScript

Property Description
constructor This returns the reference of Boolean function that created Boolean object.
prototype It generally enables us to add methods and properties in Boolean prototype.

Boolean Methods in JavaScript

Method Description
toSource() It returns the source of Boolean object in the form of a string.
toString() This method converts Boolean in to a string.
valueOf() It converts any other type in to Boolean.

Popular Tutorials