
Signature
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Thanks, my friend. I am perplexed though because I have done the
following:
<HEAD>
<script>
var myBoolean=new Boolean(true);
// Do other processing, alter value of myBoolean accordingly
</script>
</HEAD>
<BODY>
<script>
if (myBoolean) //**************
{
// Do other stuff
}
</script>
</BODY>
My browser (Netscape 6) displays an error, saying that "Error:
myBoolean is not defined" at the line marked above with the asterisks.
Whats gone wrong? It all looks fine to me....
TIA
Trev
Trev - 30 Oct 2006 19:02 GMT
I don't know if this is relevant, but the if statement in the second
script tag is encased within a function:
<BODY>
<script>
function DoMyStuff(){
if (myBoolean) //**************
{
// Do other stuff
}
}
</script>
</BODY>
Randy Webb - 30 Oct 2006 19:04 GMT
Trev said the following on 10/30/2006 12:51 PM:
> Thanks, my friend. I am perplexed though because I have done the
> following:
<snip>
> <script>
>
> var myBoolean=new Boolean(true);
var myBoolean = true;
No need for the new Boolean.
> // Do other processing, alter value of myBoolean accordingly
<snip>
> if (myBoolean) //**************
> {
> // Do other stuff
> }
<snip>
> My browser (Netscape 6) displays an error, saying that "Error:
> myBoolean is not defined" at the line marked above with the asterisks.
> Whats gone wrong? It all looks fine to me....
NS6? NS is up to version 8 and 6 is considerably old. It may be a bug in
NS6 that didn't handle new Boolean() <shrug>. Try changing it to just =
true, test it and see what happens. If it still throws the error, insert
alerts to debug it to see where it "disappears" at. And then look into
upgrading your NS :) Firefox is free and NS6/7 are based on Firefox (to
an extent anyway), and NS8 uses two rendering engines - IE and Mozilla.

Signature
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Michael Winter - 31 Oct 2006 02:51 GMT
[snip]
> var myBoolean=new Boolean(true);
[snip]
> if (myBoolean) //**************
This is unlikely to achieve what you expect. The variable, myBoolean,
will reference an object. References always evaluate to true when
type-converted to boolean so even:
new Boolean(false)
would pass that test. If you were to insist on using a Boolean object,
you would have to make use of the valueOf method:
if (myBoolean.valueOf())
to obtain the boolean value represented by the object. However, as Randy
pointed out, a boolean value will do.
[snip]
Mike