ActionScript 3中===与==及!==与!=操作符的区别
===与==操作符的区别如下:
1.全然(strict)相等的比较操作符(===)的操作只对数字类型变量的惊醒数据类型转换,
而一般相等的比较操作符(==)的操作符对所有基本数据类型进行转换。
2.使用===相等比较符来比较null和undefined,它总是返回flase(不成立)。
!==与!=操作符的区别如下:
1.全然(strict)不相等的比较操作符(!==)的操作只对数字类型变量的惊醒数据类型转换,
而一般不相等的比较操作符(!=)的操作符对所有基本数据类型进行转换。
2.使用!==相等比较符来比较null和undefined,它总是返回true(成立)。
例子源码
注意编译的时候用: xmlc -strict=false StrictComparison1.mxml
或者如果直接在flex 3编译器里 右键项目属性 Flex Compiler里增加-strict=false后 -locale en_US -strict=false
viewSourceURL=""
horizontalAlign="center" verticalAlign="middle"
width="100%" height="100%"
>
private function showProperties():void {
var a1:String = "5";
var a2:String = new String("5");
var b1:int = 5;
var b2:Number = new Number(5);
var result:Boolean;
result = a1 == a2; //result is true;
panelPropertyArea.text = "result: " + result + "\n";
result = a1 === a2; //result is true;
panelPropertyArea.text += "result: " + result + "\n";
result = a1 == b1; // result is true
panelPropertyArea.text += "result: " + result + "\n";
result = a1 == b2; // result is true
panelPropertyArea.text += "result: " + result + "\n";
result = a1 === b1; // result is false
panelPropertyArea.text += "result: " + result + "\n";
result = a1 !== b1; // result is false
panelPropertyArea.text += "result: " + result + "\n";
result = a1 === b2; // result is false
panelPropertyArea.text += "result: " + result + "\n";
result = b1 == b2; // result is true
panelPropertyArea.text += "result: " + result + "\n";
result = b1 === b2; // result is true
panelPropertyArea.text += "result: " + result + "\n";
panelPropertyArea.text += "+++++++++++++++++++++++++\n";
result = a1 != b1; // result is false
panelPropertyArea.text += "result: " + result + "\n";
result = a1 !== b1; // result is true
panelPropertyArea.text += "result: " + result + "\n";
result = a2 != b1; // result is false
panelPropertyArea.text += "result: " + result + "\n";
result = a2 !== b1; // result is true
panelPropertyArea.text += "result: " + result + "\n";
panelPropertyArea.text += "+++++++++++++++++++++++++\n";
result = null == null; // result is true
panelPropertyArea.text += "result: " + result + "\n";
result = null === null; // result is true
panelPropertyArea.text += "result: " + result + "\n";
result = null == undefined; // result is true
panelPropertyArea.text += "result: " + result + "\n";
result = null === undefined; // result is false
panelPropertyArea.text += "result: " + result + "\n";
}
]]>
paddingTop="5" paddingLeft="5" paddingRight="5" paddingBottom="5">
说明本文章是我自己来自<
原创文章转载请注明出处:云飞扬IT的blog





