Booleans

Booleans Derive their name from George Boole, the 19th century logician who developed the true/false system of logic upon which digital circuits would later be based. With this in mind, it should come as no surprise that Booleans take on one of two values. true or false .

     Comparison expressions such as a<y evaluate to a Boolean value depending  upon whether the comparison is true or false. so the condition of a control structure such as if/else is evaluated to a Boolean to determine  what code to execute. 

For example:
 if(a==y)
{
  a=a+1;
}
   
increments a by 1 if the comparison a equal to y is  true.
you can use booleans explicitly to the same effect, as in

var doIncrement = true;
if(doIncrement) 
{
a=a+1;
}  

or 

if(true)
{
a=a+1;


Booleans are commonly included as object properties indicating an  on/off state. For example, the cookieEnabled properties of Internet Explorer's Navigator object (navigator.cookieEnabled) is a Boolean that has value true when the user has persistent  cookies enabled and false otherwise. An example of accessing the property is

if(navigator.cookieEnabled)
{
alert("Persistent cookies are enabled");
}  

else
{
alert("Persistent cookies are not enabled");

Comments

Popular posts from this blog

What is Operating System?

What is MAC Address?

What is function in javascript