javascript中的==和===
1.用==作比较运算时,比较的两个值都会进行类型转换.转换规则如下:(比较的两个值分别为A和B):
a.A、B中有bool值,则比较之前会转化为数字值。false转为0, true转为1 ;
alert(false==0)//结果为true
alert("123"==123)//结果为true
alert(5==new String("5"))//结果为true
alert(new String("5") == new String("5"));//注意结果为false
alert(null == undefined);//truealert(NaN == NaN);//falsealert(NaN == 1);//false,只要比较的两者中含NaN,结果即为false
alert("5" === "5")//truealert("5" === 5);//false
var str1 = "abc";var str2 = "abc";alert(str1.indexOf(str2)==0&&str2.indexOf(str1)==0)//相等则为true,不等则为false注意此种方法区分大小写
str1.localeCompare(str2)==0//返回0则证明str1与str2相等