6/06/2007

Very strange

//Very strange / Sehr merkwürdig in Actionscript:

var a:String = '0';

var b:String = '1';

if (a == true) {

trace(a+" is true");

} else {

trace(a+" is not true");

}

if (b == true) {

trace(b+" is true");

} else {

trace(b+"is not true");

}

//Output / Ausgabe/:

//0 is not true

//1 is true

Kommentare:

christopher hat gesagt…

The same happens with JavaScript.
Try the following:

var a = new String();
a="1";
alert(typeof(a));
// String

if(a==true){
alert(a);
}
else {
alert("this would be expected");
}

// 1

def hat gesagt…

nothing strange .. Jave transform string to boolean without any function - so 1 is == true and 0 is false - so it right ///
if you need to see if string is exist . that ask that // not that it is true o false

if ( a.length > 0 )