当前位置:网站首页>JS null judgment operators | and? Usage of
JS null judgment operators | and? Usage of
2022-06-30 06:58:00 【A Xiaoming】
1. Conversion rules
Other data types are converted to boolean Type of rules :
null、undefined、‘’( The length is 0 String )、‘0’、0、NaN These are converted into false, Everything else is converted into true
2. The result of a logical operation
! The result is always true or false.
First convert the data into true or fasle, Then reverse .|| Short circuit function . ( True is true )
If The first 1 Number yes true Or it can be converted to true, The result is the first number .
If The first 1 Number yes fasle Or it can be converted to false, The result is the second number .&& Short circuit function .( True is true )
If The first 1 Number yes false Or it can be converted to false, The result is the first number .
If The first 1 Number yes true Or it can be converted to true, The result is the second number .
3. Judgment operator || and ?? Usage of
- || Operator : When a property or a value is null、undefined、false、0、 An empty string "" when , The result is || Value after
- ?? Operator : When a property or a value is null or undefined when , take ?? Value after
example :
// 0,1 On behalf of Guan , open . The default value is 1 open
let open=0
let open1 = open || 1 //0 Will be treated as false, The result is 1
let open2 = open ?? 1 //0 It won't change , The result is 0
console.log(0||1) //1
console.log(0??1) //0
console.log(""||1) //1
console.log(""??1) //""
console.log(false||1) //1
console.log(false??1) //false
console.log(null||1) //1
console.log(null??1) //1
console.log(undefined||1) //1
console.log(undefined??1) //1
边栏推荐
- 【申博攻略】五.专家推荐信模板
- How does the CPU recognize the code?
- RT thread Kernel Implementation (I): threads and scheduling
- Solr search
- C # - C # process and convert pixeldata of CT images with fo DICOM
- Definition and use of ROS topic messages
- 与MQTT的初定情缘
- 【Mask-RCNN】基于Mask-RCNN的目标检测和识别
- Problems and solutions of creating topic messages in ROS
- Basic questions (I)
猜你喜欢
随机推荐
Write a C program to judge whether the system is large end byte order or small end byte order
How does the CPU recognize the code?
[transfer] analysis of memory structure, cache and DMA architecture
Ftplib+ tqdm upload and download progress bar
Several C language implementations
Basic questions (I)
Deep learning --- the weight of the three good students' scores (3)
[Hot100]10. Regular Expression Matching
明天!“移动云杯”大赛空宣会开播!
Goland常用快捷键设置
【Hot100】11. 盛最多水的容器
我开户后把账号忘记了咋办?股票在网上开户安全吗?
Problems and solutions of creating topic messages in ROS
tomorrow! "Mobile cloud Cup" competition air publicity will start!
[my creation anniversary] one year anniversary essay
Four tips in numpy
InnoDB engine in MySQL
【Hot100】11. Container with the most water
MySQL中的InnoDB引擎
Skillfully use 5 keys to improve office efficiency









