JavaScript Boolean

JavaScript Boolean is an object that represents value in two states: true or false. You can create the JavaScript Boolean object by Boolean() constructor as given below.

Boolean b=new Boolean(value);

The default value of JavaScript Boolean object is false.

JavaScript Boolean Example

<script>  

document.write(10<20);//true  

document.write(10<5);//false  

</script>

JavaScript Boolean Properties

PropertyDescription
constructorreturns the reference of Boolean function that created Boolean object.
prototypeenables you to add properties and methods in Boolean prototype.

JavaScript Boolean Methods

MethodDescription
toSource()returns the source of Boolean object as a string.
toString()converts Boolean into String.
valueOf()converts other type into Boolean.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *