现象:使用if与switch做判断时,判断结果不同
```javascript
<script>
document.addEventListener("keydown", (event) => {
if (event.key === "ArrowUp" || "Up") {
console.log("if", event.key, "up");
} else if (event.key === "ArrowDown" || "Down") {
console.log(event.key, "down");
} else if (event.key === "ArrowLeft" || "Left") {
console.log(event.key, "left");
} else if (event.key === "ArrowRight" || "Right") {
console.log(event.key, "right");
}
switch (event.key) {
case "ArrowUp" || "Up":
console.log("switch", event.key, "up");
break;
case "ArrowDown" || "Down":
console.log("switch", event.key, "down");
break;
}
});
</script>
###### 运行结果及报错内容
控制台:
```javascript
测试.html:13 if ArrowUp up
测试.html:23 switch ArrowUp up
测试.html:13 if ArrowDown up
测试.html:26 switch ArrowDown down
测试.html:13 if ArrowLeft up
测试.html:13 if ArrowRight up
为什么所有的按键都能过 event.key === "ArrowUp" || "Up" 判断