当前位置:网站首页>[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 ?
边栏推荐
- 抽象类和接口的区别
- Flet教程之 11 Row组件在水平数组中显示其子项的控件 基础入门(教程含源码)
- 迁移/home分区
- Cs231n notes (top) - applicable to 0 Foundation
- CISP-PTE之SQL注入(二次注入的应用)
- 抽象类中子类与父类
- 16. [stm32] starting from the principle, I will show you the DS18B20 temperature sensor - four digit digital tube displays the temperature
- 详解SQL中Groupings Sets 语句的功能和底层实现逻辑
- 用键盘输入一条命令
- Reduce the cost by 40%! Container practice of redis multi tenant cluster
猜你喜欢

Single merchant v4.4 has the same original intention and strength!

Pits encountered in the use of boolean type in development

数据湖(十四):Spark与Iceberg整合查询操作

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

Use of RLOCK lock

Parameter type setting error during batch update in project SQL

Coding devsecops helps financial enterprises run out of digital acceleration

list去重并统计个数

单商户 V4.4,初心未变,实力依旧!

StarkWare:欲构建ZK“宇宙”
随机推荐
One click installation script enables rapid deployment of graylog server 4.2.10 stand-alone version
抽象类中子类与父类
vant popup+其他组件的组合使用,及避坑指南
Today's sleep quality record 79 points
ES6 drill down - ES6 generator function
公司自用的国产API管理神器
Apiccloud cloud debugging solution
Win11如何给应用换图标?Win11给应用换图标的方法
Flet教程之 11 Row组件在水平数组中显示其子项的控件 基础入门(教程含源码)
Mistakes made when writing unit tests
Research and development efficiency measurement index composition and efficiency measurement methodology
ES6 deep - ES6 class class
10分钟帮你搞定Zabbix监控平台告警推送到钉钉群
普洛斯数据中心发布DC Brain系统,科技赋能智慧化运营管理
Quelques réflexions cognitives
Record the pits encountered in the raspberry pie construction environment...
Transaction rollback exception
Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
一文带你吃透js处理树状结构数据的增删改查
项目sql中批量update的时候参数类型设置错误