当前位置:网站首页>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 …
边栏推荐
- mysql基础入门 day3 动力节点[老杜]课堂笔记
- Comparison of two ways for C to access SQL Server database (SqlDataReader vs SqlDataAdapter)
- [protobuf] protobuf generates cc/h file through proto file
- c#获取当前的时间戳
- Harmonyos actual combat - ten thousand words long article understanding service card development process
- Detailed explanation of pipline of mmdetection
- Flink SQL custom connector
- Agp7.0|kts makes a reinforced plug-in
- Why must redis exist in distributed systems?
- [wechat applet] realize applet pull-down refresh and pull-up loading
猜你喜欢
Bottomsheetbehavior principle of realizing the home page effect of Gaode map
Dart asynchronous task
100 lines of code and a voice conversation assistant
Mmdet line by line deltaxywhbboxcoder
Detailed explanation of pytoch's scatter function
Talk about how the kotlin collaboration process establishes structured concurrency
Using appbarlayout to realize secondary ceiling function
Pit encountered by fastjason
Detailed explanation of pipline of mmdetection
Wechat development tool (applet)
随机推荐
[untitled]
icon资源
Pytorch BERT
Opencv learning notes-day14 drawing of image geometry (rect class rotatedrect class, rectangle drawing rectangle circle drawing circular function line drawing line function ellipse drawing elliptic fu
Why must redis exist in distributed systems?
File upload component on success event, add custom parameters
Esp32 things (I): Preface
Concatapter tutorial
Opencv learning notes -day 12 (ROI region extraction and inrange() function operation)
Anchorgenerator for mmdet line by line interpretation
Use of Baidu face recognition API
Deep understanding of kotlin collaboration context coroutinecontext
What kind of experience is it to develop a "grandson" who will call himself "Grandpa"?
Flink sql -- No factory implements ‘org. apache. flink. table. delegation. ExecutorFactory‘.
Summary of common pytoch APIs
List set export excel table
启动jar包报错UnsupportedClassVersionError,如何修复
Opencv learning notes-day6-7 (scroll bar operation demonstration is used to adjust image brightness and contrast, and createtrackbar() creates a scroll bar function)
[untitled]
Esp32 things (VIII): music playing function of function development