当前位置:网站首页>ES6 learning path (IV) operator extension
ES6 learning path (IV) operator extension
2022-06-30 09:09:00 【Ancient dust left Taidao】
Exponential operators
const a = 3 ** 3
console.log(a) // 27
The exponential operator evaluates from right to left
const a = 1 ** 3 ** 2
console.log(a) // 1
First calculate 3 Of 2 The power is 9, Count again 1 Of 9 The power is 1
const a = 2 ** 1 ** 2
console.log(a) // 2
// First calculate 1 Of 2 The power is 1 Count again 2 Of 1 Is 2
Chain judgment operator
const obj = {
}
console.log(obj?.a) // undefined
const obj1 = {
a: 1
}
console.log(obj1?.a) // 1
obj?.a
It can be understood as obj && obj.a || undefined
obj Is there any a This attribute , If you have any, take a value , If not, take undefined
More chain operations
const obj = {
a: {
b: {
c: 1
}
}
}
const d = obj && obj.a && obj.a.b && obj.a.b.c || undefined
console.log(d) // 1
// Chain operation
const obj = {
a: {
b: {
c: 1
}
}
}
const d = obj?.a?.b?.c
console.log(d) // 1
Operation function
const obj = {
a: {
b: {
c: () => {
return 3
}
}
}
}
const d = obj?.a?.b?.c()
console.log(d) // 3
Short circuit mechanism
// Chain operation
const obj = {
a: {
b: {
}
}
}
const d = obj?.a?.b?.c
console.log(d) // undefined
// As long as there is one place where the value is undefined perhaps null, The program won't go back ( Judge ) 了
NULL Judgment operator
The classic method of setting default values
const foo = 1
const bar = foo || 100
console.log(bar) // 1
If the programmer wants to foo by undefined
perhaps null
The default value is given when 100, So there's a problem . because foo
by false
perhaps 0 Or an empty string , Default values will also be given .
If you just want foo by undefined
perhaps null
Set default value when , You can do this
const foo = ''
const bar = foo ?? undefined
console.log(bar) // ''
Other items will be added when they come across …
边栏推荐
- Opencv learning notes -day4 image pixel reading and writing operations (array traversal and pointer traversal implementation, uchar vec3b data type and mat class functions mat:: at(), mat:: ptr())
- Flink SQL custom connector
- Installation, use and explanation of vulnerability scanning tool OpenVAS
- Detectron2 source code reading 2--- using the configurable decorator to build the dataloader
- Pit encountered by fastjason
- Talk about how the kotlin process started?
- Opencv learning notes -day3 (mat object and creation related operations mat:: clone(), mat:: copyto(), mat:: zeros(), mat:: ones(), scalar()...)
- 挖财开户安全吗?怎么有人说不靠谱。
- Use Huawei performance management service to configure the sampling rate on demand
- Deeply understand the working principle of kotlin collaboration suspend (beginners can also understand it)
猜你喜欢
Use Huawei performance management service to configure the sampling rate on demand
Opencv learning notes -day10 logical operation of image pixels (usage of rectangle function and rect function and bit related operation in openCV)
Axure make menu bar effect
Wechat development tool (applet)
Opencv learning notes -day3 (mat object and creation related operations mat:: clone(), mat:: copyto(), mat:: zeros(), mat:: ones(), scalar()...)
So the toolbar can still be used like this? The toolbar uses the most complete parsing. Netizen: finally, you don't have to always customize the title bar!
Detailed explanation of pytoch's scatter function
Esp32 things (II): sharpening the knife without mistaking firewood - make preparations before project development
Opencv learning notes -day2 (implemented by the color space conversion function cvtcolar(), and imwrite image saving function imwrite())
Talk about how the kotlin process started?
随机推荐
Introduction to the runner of mmcv
14岁懂社会-《关于“工作的幸福”这件事儿》读书笔记
Opencv learning notes -day10 logical operation of image pixels (usage of rectangle function and rect function and bit related operation in openCV)
Based on svelte3 X desktop UI component library svelte UI
Mmdet line by line code interpretation of positive and negative sample sampler
Talk about writing
Flink sql -- No factory implements ‘org.apache.flink.table.delegation.ExecutorFactory‘.
Harmonyos actual combat - ten thousand words long article understanding service card development process
Is it safe to open an account? How can anyone say that it is not reliable.
[data analysis and display]
JVM调优相关命令以及解释
Resnet50+fpn for mmdet line by line code interpretation
Raspberry pie 4B no screen installation system and networking using VNC wireless projection function
Understanding society at the age of 14 - reading notes on "happiness at work"
Six implementation methods of singleton mode
[untitled]
Qt连接神通数据库
技术管理进阶——管理者如何进行梯队设计及建设
icon资源
Detailed explanation of pipline of mmdetection