使用 === 和 !== 代替 == 和 !=
比较运算符进行计算时会利用ToBoolean方法进行强制转换数据类型,并遵从以下规则:
Object的计算值是true
Undefined的计算值是false
Boolean计算值是boolean的值
Numbers如果是-0,+0或者NaN,则计算值是false反之则是true
String如果是空,则计算值是false,反之则是true
if([0]){
//true
}
使用快捷方式
//bad
if(name !== ''){
}
//good
if(name){
}
//bad
if(collection.length >0){
}
//good
if(collection.length){
}
//God bless!
1:9 And God said,Let the water under the heaven be gathered together unto one place,and let the dry land appear:and it was so .