Javascript Booleans

Boolean is an object that represents value in two states: true or false.

Booleans can be objects

We can create the JavaScript Boolean object by Boolean() constructor as given below:-

    Boolean b=new Boolean(value);  

Note:- The Boolean value of an expression is the basis for all JavaScript comparisons and conditions.

    var a = false;  
    var b = new Boolean(true);
    document.writeln("Type of a is ", typeof(a));
    document.writeln("<br/> Type of b is ", typeof(b));


Comparison and Conditions

We can evaluate to any value using comparison operators. Below are the some examples for those operator:-

> greater thanif (salary > 4000)
< less thanif (age < 30)
==equal toif (day == “Sunday”)

Boolean Examples

Below are some of the examples which illustrate the usage of Boolean.

    var a, b = null, c = 20 / "B";
    document.write("a ",Boolean(a));
    document.write("<br/>b ",Boolean(b)); 
    document.write("<br/>c ",Boolean(c)); 
    document.write("<br/>10<20 ",10<20);  
    document.write("<br/>10<5 ",10<5);