Tutorials » Javascript tutorials »

The Boolean Object


This article explains about JavaScript Boolean Object



Boolean is a primitive data type in JavaScript that holds the entity either true or false.

We can say Boolean object as a package or wrapper for boolean value. Don’t get confuse with boolean data type and boolean object.

boolean object is defined using new keyword .It is used to convert a non-boolean value to a boolean value (true or false).

Defining a boolean object



syntax: var boolVar=new Boolean()

The above code defines new Boolean object.

If we pass no intial value, 0, -0, null,"" false, undefined or NAN then it will evaluate to false. Otherwise it’s true. But remember that if we pass this value to an if condition then it will return true.

That is for example

All the below lines of code create boolean objects with an initial value of false:

var boolVar=new Boolean()
var boolVar=new Boolean(0)
var boolVar=new Boolean(null)
var boolVar=new Boolean("")
var boolVar=new Boolean(false)
var boolVar=new Boolean(NaN)

All the below lines of code assigns boolean objects with an initial value of true:

var boolVar=new Boolean(true)
var boolVar=new Boolean("true")
var boolVar=new Boolean("false")
var boolVar=new Boolean("Richard")





Next Chapter: Boolean Object - An Example
Previous Chapter: Math Object - Example
More Chapters: Javascript Tutorials
More Tutorials: Tutorial Index



Top Contributors
Today
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    SivS
    More...
     
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India