当前位置:网站首页>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
边栏推荐
- volatile 关键字的三大特点【数据可见性、指令禁止重排性、不保证操作原子性】
- try --finally
- rdma 编程详解
- SQL学习|基础查询与排列
- 异常记录-21
- openvswitch vlan网络实践
- Decentralized Collaborative Learning Framework for Next POI Recommendation
- 用Future与CountDownLatch实现多线程执行多个异步任务,任务全部完成后返回结果
- Use the SED command to process text efficiently
- [MySQL basics] startup options and configuration files
猜你喜欢

Prometheus Cortex使用Block存储时的相关问题

Batch modify / batch update the value of a field in the database

volatile 关键字的三大特点【数据可见性、指令禁止重排性、不保证操作原子性】

SQL学习|集合运算

Installing redis using a small leather panel in the window environment

ebfp编程常用API介绍

Introduction to DDoS attack / defense

MySQL索引【数据结构+索引创建原则】

SQL学习|窗口函数

关于 synchronized、ThreadLocal、线程池、Atomic 原子类的 JUC 面试题
随机推荐
关于Postgres主从复制延迟监控的错误告警问题
Basic concepts of database: OLTP / OLAP / HTAP, RPO / RTO, MPP
Virtio and Vhost_ Net introduction
Prometheus Cortex使用Block存储时的相关问题
postMan 传参总结
Get DOM element location information by offset and client
【代码解析(3)】Communication-Efficient Learning of Deep Networks from Decentralized Data
【代码解析(7)】Communication-Efficient Learning of Deep Networks from Decentralized Data
【ES6快速入门】
基于DPDK实现VPC和IDC间互联互通的高性能网关
Solution to page cache problem (use with caution)
Typescript (top)
如何使用TiUP部署一个TiDB v5.0集群
MySQL 【读写锁+表锁+行锁+MVCC】
Centos8 builds php8 0.3 operating environment
surprise库中evaluate函数弃用解决方法
Thanos Compact组件测试总结(处理历史数据)
Common views of Oracle database performance analysis
使用prom-label-proxy实现Prometheus Thanos的基于标签的多租户读
异常记录-14