当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Imitation scallop essay reading page
JS regular matching first assertion and last assertion
【代码解析(4)】Communication-Efficient Learning of Deep Networks from Decentralized Data
Unix期末考试总结--针对直系
Analysis of Rdam principle
[no steps in a small step to a thousand miles] Oracle Application derivative ora-01455 error reporting processing
Oracle net service: listener and service name resolution method
PHP background parsing after JQ serialization
【代码解析(7)】Communication-Efficient Learning of Deep Networks from Decentralized Data
try --finally
Alertmanager重复/缺失告警现象探究及两个关键参数group_wait和group_interval的释义
Installing redis using a small leather panel in the window environment
Basic concepts of database: OLTP / OLAP / HTAP, RPO / RTO, MPP
使用sed命令来高效处理文本
【MySQL基础篇】启动选项与配置文件
Ansible basic commands, roles, built-in variables and tests judgment
Typescript (lower)
如何通过dba_hist_active_sess_history分析数据库历史性能问题
DNA reveals surprise ancestry of mysterious Chinese mummies
[step by step, even thousands of miles] MySQL reports a large number of unauthenticated user connection errors