当前位置:网站首页>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 …
边栏推荐
- JPA naming rules
- Torchvision loads the weight of RESNET except the full connection layer
- Using appbarlayout to realize secondary ceiling function
- Rew acoustic test (IV): test principle of rew
- C accesses mongodb and performs CRUD operations
- [cmake] make command cannot be executed normally
- Abstract factory pattern
- Detailed explanation of pytoch's scatter function
- Invalid update: invalid number of sections. The number of sections contained in the table view after
- Esp32 things (VIII): music playing function of function development
猜你喜欢

Harmonyos actual combat - ten thousand words long article understanding service card development process

Flink Exception -- No ExecutorFactory found to execute the application

技术管理进阶——管理者如何进行梯队设计及建设

Installation, use and explanation of vulnerability scanning tool OpenVAS

Metasploit practice - SSH brute force cracking process

快应用中实现自定义抽屉组件

Flink SQL custom connector

Interpretation of orientedrcnn papers

Duplicate entry '2' for key 'primary appears in JPA‘

Based on svelte3 X desktop UI component library svelte UI
随机推荐
Common query and aggregation of ES
Rew acoustic test (V): equipment required for test
C#访问MongoDB并执行CRUD操作
Rew acoustic test (II): offline test
Implementing custom drawer component in quick application
【付费推广】常见问题合集,推荐榜单FAQ
JPA naming rules
Talk about the kotlin cooperation process and the difference between job and supervisorjob
启动jar包报错UnsupportedClassVersionError,如何修复
Codeworks 5 questions per day (1700 for each) - the third day
Maxiouassigner of mmdet line by line interpretation
El input limit can only input numbers
icon资源
Deep understanding of kotlin collaboration context coroutinecontext
Opencv learning notes -day10 logical operation of image pixels (usage of rectangle function and rect function and bit related operation in openCV)
Flink sql -- No factory implements ‘org. apache. flink. table. delegation. ExecutorFactory‘.
Comparison of two ways for C to access SQL Server database (SqlDataReader vs SqlDataAdapter)
C accesses mongodb and performs CRUD operations
vite項目require語法兼容問題解决require is not defined
14岁懂社会-《关于“工作的幸福”这件事儿》读书笔记