Boolean

The JavaScript Boolean object is the data type for boolean values(true or false). Boolean values are used by programmers of many languages as a way in which they can toggle between true and false in a variable or evaluate expressions. Many expressions in Javascript will result in a boolean value which you can then evaluate using condition logic.

You do not have to use the “new Boolean()” constructor syntax and it is said to be more efficient NOT to use the constructor when establishing boolean objects.

// Booleans with false value
var a = false;

 

var b = Boolean();

 

var c = Boolean(false);

 

var d = new Boolean(false);

 

var e = new Boolean(null);

 

var f = new Boolean("");

 

var g = new Boolean(0); // Booleans with true value

 

var h = true;

 

var i = Boolean(true);

 

var j = new Boolean(true);

 

var k = new Boolean(1);

 

var l = new Boolean("poop");

 

 

All of the approaches shown above will establish Boolean objects in Javascript with initial values of either true or false.

Example demonstrating how to evaluate Boolean objects using an if condition:

var a = false;

 

if(a){

 

document.write("a is "+a+", run code"); // "a" must be true for code to run

 


}

renewdev

I Am Developer And Want To Share My Knowledge With The World..:) ;) . I Have Another Social Networking Website (Renewchat) And For Designing Or Developing Of Website Purpose You Can Contact Me On Renew Coder .. :) ;)

Leave a Reply

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