当前位置:网站首页>switch case时连写常规判断表达式的错误 case和if并用 l
switch case时连写常规判断表达式的错误 case和if并用 l
2022-04-23 06:02:00 【NOyesNONO_】
let a = 5
let b = 6
switch (a) {
case 3:
console.log('a为3');
break;
case 4:
console.log('a为4');
break;
case (5 && b === 6):
console.log('a为5且b为6');
break;
case 5:
console.log('a为5'); //输出
break;
}
想象情况:输出a为5且b为6
实际情况:case后边:是将表达式与switch后面的值与其比较得出一个true或false。
先进行了这个表达式的计算 5 && b === 6
//是true,5转为布尔值是true 而a === true
是false
可以写成
let a = 5
let b = 6
switch (a) {
case 3:
console.log('a为3');
break;
case 4:
console.log('a为4');
break;
case 5:
if (b === 6) {
console.log('a为5且b为6');
}
break;
case 5:
console.log('a为5'); //输出
break;
}
版权声明
本文为[NOyesNONO_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/NOyesNONO_/article/details/121117199
边栏推荐
- 异常记录-18
- tensorflow下载
- 重启Oracle监听器会中断已有连接吗
- Passerelle haute performance pour l'interconnexion entre VPC et IDC basée sur dpdk
- [no steps in a small step to a thousand miles] Oracle Application derivative ora-01455 error reporting processing
- 【MySQL基础篇】启动选项、系统变量、状态变量
- Oracle性能分析工具:OSWatcher
- Practice of openvswitch VLAN network
- 【代码解析(6)】Communication-Efficient Learning of Deep Networks from Decentralized Data
- 异常记录-7
猜你喜欢
随机推荐
【不积跬步无以至千里】MySQL报大量unauthenticated user连接错误
用反射与注解获取两个不同对象间的属性值差异
openvswitch 编译安装
Oracle数据库性能分析之常用视图
Kids and COVID: why young immune systems are still on top
Concurrent optimization request
Binary sum of leetcode questions
LeetCode刷题|897递增顺序搜索树
bcc安装和基本工具使用说明
Virtio and Vhost_ Net introduction
Decentralized Collaborative Learning Framework for Next POI Recommendation
【OSS文件上传快速入门】
Typescript (top)
MySQL server standalone deployment manual
[fish in the net] ansible awx calls playbook to transfer parameters
Working principle and practice of browser
Ansible基本命令、角色、内置变量与tests判断
异常记录-9
[OSS file upload quick start]
[no steps in a small step to a thousand miles] Oracle Application derivative ora-01455 error reporting processing