Boolean : Boolean « Number Data Type « JavaScript Tutorial

Home
JavaScript Tutorial
1.Language Basics
2.Operators
3.Statement
4.Development
5.Number Data Type
6.String
7.Function
8.Global
9.Math
10.Form
11.Array
12.Date
13.Dialogs
14.Document
15.Event
16.Location
17.Navigator
18.Screen
19.Window
20.History
21.HTML Tags
22.Style
23.DOM Node
24.Drag Drop
25.Object Oriented
26.Regular Expressions
27.XML
28.GUI Components
29.Dojo toolkit
30.jQuery
31.Animation
32.MS JScript
JavaScript Tutorial » Number Data Type » Boolean 
5.2.1.Boolean

The Boolean object is a wrapper object that holds a primitive Boolean value.

The Boolean object provides a method for converting the value to a string.

A primitive boolean can have only one of two states: true or false.

JavaScript uses the number 1 to represent true and 0 to represent false but provides the toString() method to return the strings "true" and "false".

A Boolean object is created with the Boolean() constructor and the new operator or by the Boolean() function.

Constructor:

var variable = new Boolean(value)
    var variable = Boolean(value)

value is the value to be converted to a Boolean value and stored in the object.

The values null, NaN, "" (empty string), and 0 (zero) are converted to false.

All other values (including the string "false") are converted to true.

If the new operator is used, the new Boolean object is returned.

If the Boolean() function is used, the primitive Boolean value is returned.

Method toString() returns a string representation of the primitive Boolean value.

If the object contains true, the string "true" is returned.

If the object contains false, the string "false" is returned.

<HTML>
<BODY>
<SCRIPT language="JavaScript">
<!--
var myVariable=false;
document.write(myVariable);

//-->
</SCRIPT>
</BODY>
</HTML>
5.2.Boolean
5.2.1.Boolean
5.2.2.Boolean Object Verses Primitive Boolean Value
5.2.3.Boolean.prototype
5.2.4.Boolean.toSource()
5.2.5.Boolean.toString()
5.2.6.Boolean.valueOf()
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.