JS References

JS Objects
JS HTML DOM

Suscriber with us



Receive HTML?

Syndicate

JS Boolean PDF Print E-mail

The Boolean object is used to convert a non-Boolean value to a Boolean value (true or false).

Boolean Object

The Boolean object is an object wrapper for a Boolean value.

The Boolean object is used to convert a non-Boolean value to a Boolean value (true or false).

We define a Boolean object with the new keyword. The following code line defines a Boolean object called myBoolean:

var myBoolean=new Boolean();

Note: If the Boolean object has no original value or if it is 0, -0, null, "", false, undefined, or NaN, the object is set to false. Otherwise it is true (even with the string "false")!

How to Check if a Boolean object is true or false?

<!--Created By phpguru.biz-->

var p1=new Boolean( 0);
var p3=new Boolean("");
var p4=new Boolean(null);
document.write("0 is boolean "+ p1 +"<br />");
document.write("An empty string is boolean "+ p3 + "<br />");
document.write("null is boolean "+ p4+ "<br />");

<!--Created By phpguru.biz-->

All the following lines of code create Boolean objects with an initial value of false:

var myBoolean=new Boolean();
var myBoolean=new Boolean(0);
var myBoolean=new Boolean(null);
var myBoolean=new Boolean("");
var myBoolean=new Boolean(false);

var myBoolean=new Boolean(NaN); 

And all the following lines of code create Boolean objects with an initial value of true:

var myBoolean=new Boolean(true);
var myBoolean=new Boolean("true");
var myBoolean=new Boolean("false");

var myBoolean=new Boolean("Richard");

Examples

Check Boolean value
Check if a Boolean object is true or false.





Digg!Del.icio.us!Google!Live!Facebook!Slashdot!Technorati!StumbleUpon!Newsvine!Yahoo!Free social bookmarking plugins and extensions for Joomla! websites!
Last Updated ( Wednesday, 19 March 2008 )
 
< Prev   Next >

Polls

Which is the best Scripting language?