当前位置:网站首页>[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 ?
边栏推荐
- Five common negotiation strategies of consulting companies and how to safeguard their own interests
- 搜索 正排索引 和 倒排索引 区别
- [graduation season] as a sophomore majoring in planning, I have something to say
- [vulnerability warning] cve-2022-26134 conflict Remote Code Execution Vulnerability POC verification and repair process
- ES6 drill down - Async functions and symbol types
- Intel 13th generation Raptor Lake processor information exposure: more cores, larger cache
- 阿掌的怀念
- 开发中Boolean类型使用遇到的坑
- 对象和类的关系
- ES6深入—ES6 Class 类
猜你喜欢
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
Parameter type setting error during batch update in project SQL
抽象类和接口的区别
Win11如何给应用换图标?Win11给应用换图标的方法
Single merchant v4.4 has the same original intention and strength!
Use of RLOCK lock
写单元测试的时候犯的错
PSPNet | 语义分割及场景分析
ES6深入—ES6 Class 类
Intelligent metal detector based on openharmony
随机推荐
Which keywords will conflict with the abstract keyword
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
记一次'非常诡异'的云安全组规则问题排查过程
vant tabbar遮挡内容的解决方式
Mistakes made when writing unit tests
The memory of a Zhang
五种常见的咨询公司谈判策略以及如何维护自己的利益
One click installation script enables rapid deployment of graylog server 4.2.10 stand-alone version
vulnhub-FirstBlood
公司自用的国产API管理神器
有序链表集合求交集 方法 总结
抽象类中子类与父类
单商户 V4.4,初心未变,实力依旧!
搜索 正排索引 和 倒排索引 区别
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
【毕业季】作为一名大二计科在校生,我有话想说
[deep learning] how does deep learning affect operations research?
事务回滚异常
Flet教程之 09 NavigationRail 基础入门(教程含源码)
Background system sending verification code function