HTML and CSS Reference
In-Depth Information
Figure 9.37
Using the
toFixed() Number
method: Output from Example 9.32.
The
Boolean
object was included in JavaScript 1.1. It is used to convert a non-Boolean
value to a Boolean value, either
true
or
false
. There is one property, the
prototype
prop-
erty, and one method, the
toString()
method, which converts a Boolean value to a string;
thus,
true
is converted to
“true”
and
false
is converted to
“false”
.
FORMAT
var object = new Boolean(value);
EXAMPLE
var b1 = new Boolean(5);
var b2 = new Boolean(null);
EXAMPLE
9.33
<html>
<head><title>Boolean Object</title></head>
<body bgcolor=aqua>
<font face="arial" size="+1"><b>
The Boolean Object<br />
<small>
<script type="text/javascript">
1
var bool1= new Boolean( 0);
var bool2 = new Boolean(1);
var bool3 = new Boolean("");
var bool4 = new Boolean(null);
var bool5 = new Boolean(NaN);
2
document.write("The value 0 is boolean " + bool1 + "<br>");
document.write("The value 1 is boolean " + bool2 + "<br>");
document.write("The value of the empty string is boolean " +
bool3 + "<br />");
document.write("The value of null is boolean " + bool4 +
"<br />");
Continues