当前位置:网站首页>[js] skill simplification if empty judgment
[js] skill simplification if empty judgment
2022-07-05 16:28:00 【533_】
List of articles
1. Simplify the conditional expression
// Too long logical expression
if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') {
// Other logic
}
// Abbreviation
if (['abc', 'def', 'ghi', 'jkl'].includes(x)) {
// Other logic
}
simplify if … else
// Novice writing
let test= boolean;
if (x > 100) {
test = true;
} else {
test = false;
}
// Shorthand expression
let test = (x > 10) ? true : false;
// More directly
let test = x > 10;
console.log(test);
Leave blank and set the default value
if (first !== null || first !== undefined || first !== '') {
let second = first;
}
// Abbreviation
let second = first || '';
For so many years JavaScript , I don't know these skills yet ?
边栏推荐
- Is it safe for Guotai Junan to open an account online
- 抽象类中子类与父类
- One click installation script enables rapid deployment of graylog server 4.2.10 stand-alone version
- 2020-2022 two-year anniversary of creation
- [graduation season] as a sophomore majoring in planning, I have something to say
- Pspnet | semantic segmentation and scene analysis
- 项目sql中批量update的时候参数类型设置错误
- Cartoon: what is service fusing?
- Cs231n notes (medium) -- applicable to 0 Foundation
- Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
猜你喜欢
Mistakes made when writing unit tests
Today's sleep quality record 79 points
项目sql中批量update的时候参数类型设置错误
Spring Festival Limited "forget trouble in the year of the ox" gift bag waiting for you to pick it up~
ES6 drill down - Async functions and symbol types
Oneforall installation and use
服务器的数据库连不上了2003,10060“Unknown error“【服务已起、防火墙已关、端口已开、netlent 端口不通】
OneForAll安装使用
The database of the server is not connected to 200310060 "unknown error" [the service is up, the firewall is off, the port is on, and the netlent port is not connected]
Parameter type setting error during batch update in project SQL
随机推荐
How can programmers improve their situation?
后台系统发送验证码功能
DeSci:去中心化科学是Web3.0的新趋势?
ES6 drill down - Async functions and symbol types
[深度学习][原创]让yolov6-0.1.0支持yolov5的txt读取数据集模式
Pspnet | semantic segmentation and scene analysis
Intel 13th generation Raptor Lake processor information exposure: more cores, larger cache
Enterprise backup software Veritas NetBackup (NBU) 8.1.1 installation and deployment of server
10 minutes to help you get ZABBIX monitoring platform alarm pushed to nail group
《MongoDB入门教程》第04篇 MongoDB客户端
ES6深入—ES6 Class 类
vulnhub-FirstBlood
Query the latest record in SQL
tf.sequence_mask函数讲解案例
Reduce the cost by 40%! Container practice of redis multi tenant cluster
21. [STM32] I don't understand the I2C protocol. Dig deep into the sequence diagram to help you write the underlying driver
【漏洞预警】CVE-2022-26134 Confluence 远程代码执行漏洞POC验证与修复过程
RLock锁的使用
Replknet: it's not that large convolution is bad, but that convolution is not large enough. 31x31 convolution. Let's have a look at | CVPR 2022
一键安装脚本实现快速部署GrayLog Server 4.2.10单机版