(面向c#開發(fā)人員) 編寫javascript的好習(xí)慣四 比較運(yùn)算符
比較運(yùn)算符一般指的是 ==
在javascript里面以下值是等價(jià)的
alert(0 == ''); //true
alert(0 == '0'); //ture
alert(false == '0'); //ture
alert(null == undefined); //ture
alert(0 == '\t\r\n'); //ture
這個(gè)javascript的 == 號真是混亂的讓人想死。。。。
正確的做法是在javascript使用 === 來在比較值
alert(0 === 0); //true
alert(0 === '0'); //false
對應(yīng)的不等于號是 !==
PS:引用自mix11
浙公網(wǎng)安備 33010602011771號