JavaScript- The Boonlean Object!

Posted on 03/10/2009 by

0



The Boonlean Object allows the creation of the user define all Boonlean values. You can declare the object “myTrue” to represent the Boonlean value true and object myFalse to represent the Bonnlean value false. It can be done in the following manner!

For Example

myTrue = new Boonlean(true)
myFalse = new Boonlean(false)

Now you will be able to use the Objects myTrue and myFalse as Boonlean true and Boonlean false respectively.

Consider the following program.

<HTML>
<HEAD>
<TITLE> The Boonlean Object </TITLE>
</HEAD>
<BODY>
<H3 ALIGN = “CENTER”> Using the Boonlean Object </H3> <HR>
<PRE>
<SCRIPT> LANGUAGE= “JavaScript”>
myTrue= new  Boonlean(true)
myFalse= new Boonlean(false)
document.write(“true + true :\t”)
document.write(true + true)
document.write(“<BR>”)
document.write(“myTrue + myTrue :\t”)
document.write(myTrue + myTrue)
document.write(“<BR>”)
document.write(“true + false :\t”)
document.write(true + false)
document.write(“<BR>”)
document.write(“myTrue + myFalse :\t”)
document.write(myTrue + myFalse)
document.write(“<BR>”)
document.write(“false + false :\t”)
document.write(false + false)
document.write(“<BR>”)
document.write(“myFalse + myFalse :\t”)
document.write(myFalse + myFalse)
</SCRIPT>
</PRE>
</BODY>
</HTML>

JavaScript also automatically converts the Boonlean values true and false to 1 and 0 respectively, when used in numerical expreesions.

Example:

Input

true + true =2
true + false =1
false + false =0

Similarly,

myTrue + mytrue =2
myTrue + myFalse =1
myFalse + myFalse =0

Output

Using The Boonlean Object

true + true  2
myTrue + myTrue  2
true + false  1
myTrue + myFlalse  1
false + false  0
myFalse + myFalse  0

EllaHax

Advertisements
Posted in: JavaScript