当前位置:网站首页>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 …
边栏推荐
- Esp32 things (II): sharpening the knife without mistaking firewood - make preparations before project development
- Flink 数据偶尔数据积压导致checkpoint失败
- Dart asynchronous task
- Why must redis exist in distributed systems?
- Common query and aggregation of ES
- Flutter theme (skin) changes
- Set, map and modularity
- Opencv learning notes -day10 logical operation of image pixels (usage of rectangle function and rect function and bit related operation in openCV)
- [protobuf] protobuf generates cc/h file through proto file
- Opencv learning notes-day5 (arithmetic operation of image pixels, add() addition function, subtract() subtraction function, divide() division function, multiply() multiplication function
猜你喜欢

asdsadadsad

Opencv learning notes-day5 (arithmetic operation of image pixels, add() addition function, subtract() subtraction function, divide() division function, multiply() multiplication function

Pytorch BERT

Use Huawei performance management service to configure the sampling rate on demand

Find the number that appears only once in the array
![[untitled]](/img/45/368c41a74bf0738369c58c5963fca0.jpg)
[untitled]

Concatapter tutorial

Opencv learning notes -day2 (implemented by the color space conversion function cvtcolar(), and imwrite image saving function imwrite())

Mmcv expanding CUDA operator beginner level chapter

Sort (simple description)
随机推荐
[untitled]
Unsupportedclassversionerror is reported when starting jar package. How to repair it
Based on svelte3 X desktop UI component library svelte UI
[paid promotion] collection of frequently asked questions, FAQ of recommended list
Using appbarlayout to realize secondary ceiling function
Flink Exception -- No ExecutorFactory found to execute the application
Do you want the dialog box that pops up from the click?
Deep understanding of continuation principle
Alcohol tester scheme: what principle does the alcohol tester measure alcohol solubility based on?
Flutter theme (skin) changes
JPA naming rules
Understanding of MVVM and MVC
Rew acoustic test (III): generate test signal
Maxiouassigner of mmdet line by line interpretation
Torchvision loads the weight of RESNET except the full connection layer
C#访问SQL Server数据库两种方式的比较(SqlDataReader vs SqlDataAdapter)
Esp32 (7): I2S and I2C drivers for function development
mysql基础入门 动力节点[老杜]课堂作业
Flink sql -- No factory implements ‘org.apache.flink.table.delegation.ExecutorFactory‘.
C#訪問SQL Server數據庫兩種方式的比較(SqlDataReader vs SqlDataAdapter)