1、7個“坑” 2、避免坑的原則 (1)如果兩邊有true或者false,千萬不要使用== (2)如果兩邊有[],''或者0,千萬不要使用== (3)最好都使用 ,來避免強制轉換的坑! ...
1、7個“坑”
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>JavaScript完整性檢查</title>
</head>
<body>
<script type="text/javascript">
console.log('0' == false); //true
console.log(false == 0); //true
console.log(false == ''); //true
console.log(false == []); //true
console.log('' == 0); //true
console.log('' == []); //true
console.log(0 == []); //true
</script>
</body>
</html>
2、避免坑的原則
(1)如果兩邊有true或者false,千萬不要使用==
(2)如果兩邊有[],''或者0,千萬不要使用==
(3)最好都使用===,來避免強制轉換的坑!