Previous Example-|-Next Chapter's Examples-|-Return to Chapter Listing

Example 11.8:
Using the Boolean() Object

[This example works with Netscape Navigator 3 and Internet Explorer 3. Some preview versions of Netscape Navigator 4 don't like it.]

We've created some Boolean() objects, then displayed the contents of each object:


We have this script in the BODY: <script language="JAVASCRIPT"> <!-- var sBool1 = "any old text" var sBool2 bBool1 = new Boolean(sBool1) bBool2 = new Boolean(sBool2) bBoolEmpty = new Boolean() bBoolEmptyString = new Boolean("") bBoolNull = new Boolean(null) bBoolFalse = new Boolean(false) bBoolTrue = new Boolean(true) bBoolFalseString = new Boolean("false") bBoolZero = new Boolean(0) bBoolFive = new Boolean(5) document.write("This object comes from a variable that contains text: <b>" + bBool1 + "</b><br>") document.write("This object comes from a variable with nothing in it: <b>" + bBool2 + "</b><br>") document.write("This object was not given data when created: <b>" + bBoolEmpty + "</b><br>") document.write("This object was given quotation marks with nothing between them: <b>" + bBoolEmptyString + "</b><br>") document.write("This object was given null: <b>" + bBoolNull + "</b><br>") document.write("This object was given the word false, not in quotation marks: <b>" + bBoolFalse + "</b><br>") document.write("This object was given the word true, not in quotation marks: <b>" + bBoolTrue+ "</b><br>") document.write("This object was given the word false, in quotation marks: <b>" + bBoolFalseString + "</b><br>") document.write("This object was given the number 0: <b>" + bBoolZero + "</b><br>") document.write("This object was given the number 5: <b>" + bBoolFive + "</b><br>") //--> </script>
Previous Example-|-Next Chapter's Examples-|-Return to Chapter Listing