/    /  Javascript-Boolean

Javascript-Boolean

 

JavaScript Boolean is an object and this object represents value in two states:

1.true or

2.false

 

Create the JavaScript Boolean object by using Boolean() constructor:

 

Boolean b=new Boolean(value); 

 

Example:

 

<!DOCTYPE html>
<html>
<body>

<p>Display the value of 110 > 119:</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
 document.getElementById("demo").innerHTML = 110 > 119;
}
</script>

</body>
</html>

 

OUTPUT:

 

Display the value of 110 > 119:

false

 

Example:

 

<!DOCTYPE html>
<html>
<body>

<p>Display the value of 100 > 69:</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
 document.getElementById("demo").innerHTML = 100 > 69;
}
</script>

</body>
</html>

 

OUTPUT:

 

Display the value of 100 > 69:

true

 

JavaScript Boolean Properties:

 

Property         Description

 

constructor      Created Boolean object.

prototype        Add properties and methods in Boolean prototype.

 

JavaScript Boolean Methods:

 

Method          Description

 

toSource()       Source of Boolean object as a string.

toString()         converts Boolean into String.

valueOf()         converts other type into Boolean.