[thelist] JS Boolean Object...
James Aylard
evolt at pixelwright.com
Thu Dec 4 15:23:37 CST 2003
jsWalter wrote:
> I am trying to figure out how I can do this...
>
> bolValue = someFunc ( someVar );
>
> if ( bolValue ) // true
> // do something here
> else
> alert ( bolValue.err );
Have someFunc return a Boolean value, either true or false (or else a value
than can be evaluated to either true or false [1]):
function someFunc(myVar)
{
if ("Blue" == myVar)
{
return true ;
}
return false ;
}
1. Keep in mind that any expression that evaluates to 0, null, undefined, or
an empty string is interpreted as false, and that any expression that
evaluates to any other value is interpreted as true. So, in the example that
you provided in your second post -- where you evaluated "true" as a string
value -- both "true" and "false", as strings, will evaluate to true, which
you almost certainly don't want.
James Aylard
More information about the thelist
mailing list