当前位置:网站首页>[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 ?
边栏推荐
- 21. [STM32] I don't understand the I2C protocol. Dig deep into the sequence diagram to help you write the underlying driver
- Seaborn draws 11 histograms
- 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
- Convert obj set to entity set
- Desci: is decentralized science the new trend of Web3.0?
- 阿掌的怀念
- 项目sql中批量update的时候参数类型设置错误
- 研发效能度量指标构成及效能度量方法论
- 英特尔第13代Raptor Lake处理器信息曝光:更多核心 更大缓存
- Migrate /home partition
猜你喜欢
Five common negotiation strategies of consulting companies and how to safeguard their own interests
2020-2022 two-year anniversary of creation
中间表是如何被消灭的?
Flet教程之 11 Row组件在水平数组中显示其子项的控件 基础入门(教程含源码)
项目中批量update
有序链表集合求交集 方法 总结
ES6深入—async 函数 与 Symbol 类型
17. [stm32] use only three wires to drive LCD1602 LCD
[Netease Yunxin] research and practice of super-resolution technology in the field of real-time audio and video
Single merchant v4.4 has the same original intention and strength!
随机推荐
迁移/home分区
Query the latest record in SQL
Research and development efficiency measurement index composition and efficiency measurement methodology
超分辨率技术在实时音视频领域的研究与实践
求解汉诺塔问题【修改版】
Reduce the cost by 40%! Container practice of redis multi tenant cluster
极坐标扇图使用场景与功能详解
Cs231n notes (medium) -- applicable to 0 Foundation
list去重并统计个数
OneForAll安装使用
The new version of effect editor is online! 3D rendering, labeling, and animation, this time an editor is enough
Cartoon: what is blue-green deployment?
Using graylog alarm function to realize the regular work reminder of nail group robots
Apiccloud cloud debugging solution
What is the difference between EDI license and ICP business license
公司自用的国产API管理神器
Win11如何给应用换图标?Win11给应用换图标的方法
Win11提示无法安全下载软件怎么办?Win11无法安全下载软件
记一次'非常诡异'的云安全组规则问题排查过程
Intel 13th generation Raptor Lake processor information exposure: more cores, larger cache