当前位置:网站首页>Deconstruction assignment of variables
Deconstruction assignment of variables
2022-06-25 14:17:00 【Rabbit^-^】
Deconstruction and assignment of variables
To reduce the definition of variables , And it's easier to extract values from arrays or objects ,ES6 Deconstruction assignment
Deconstruction and assignment of arrays
let[a,b,c]=[1,2,3]
console.log(a)//1
console.log(b)//2
console.log(c)//3
You can omit variables
Can be used with the extension operator
let[a,...b]=[1,2,3,4,5]
console.log(a)//1
console.log(b)//[2, 3, 4, 5]
You can define default values
let[a,b,c=0]=[1,2]
console.log(a)//1
console.log(b)//2
console.log(c)//0
Other variables to which the deconstruction assignment can be applied
let[a,c=a]=[1]
console.log(a)//1
console.log(c)//1
Pay attention to the situation
1. The types before and after the deconstruction assignment correspond to
let[a]=null// Report errors
let[a]={}// Report errors
2.undefined Default values cannot be replaced
let[a=0]=[null]//null
let[a=0]=[undefined]//0
3. Reference extension operators and other variables assigned by deconstruction , You can't write backwards
let[...a,b]=[1,2,3,4]// Report errors
let[c=a,a=1]=[]// Report errors
Object and deconstruction assignment
Basic usage
let{name,sex} ={name:" Zhang Liang ",sex:" male "}
console.log(name)// Zhang Liang
console.log(sex)// male
Aliasing objects
let{name:a,sex:b} ={name:" Zhang Liang ",sex:" male "}
console.log(a)// Zhang Liang
console.log(b)// male
You can define default values
let{name:a,sex:b,age=22} ={name:" Zhang Liang ",sex:" male "}
console.log(age)//22
Resolution of nested objects
var {name,mon:[a,b,c]}={name:" Zhang ",mon:[2000,3000,1000]}
console.log(name)// Zhang
console.log(a)//2000
console.log(b)//3000
console.log(c)//1000
Deconstruction and assignment of strings
Parse the value of the string
var [...arr]="hello"
console.log(arr)//[h,e,l,l,o]
Resolve the properties and methods under the object
var {length}="hello"
console.log(length)//5
Parameter deconstruction assignment under function
When parameters are deconstructed for an array
function fun([a,b,c]){
console.log(a)
console.log(b)
console.log(c)
}
fun(1,2,3)
When a parameter is deconstructed for an object
function fun1({name:a,age:b}){
console.log(a+","+b)
}
fun1({name:"z",age:23})
Be careful : When the value after the deconstruction assignment is of other types , First consider whether this type can be converted into an object , Otherwise, it cannot be parsed
New attribute method under reference type
Digital extension
0b10101// Define binary
0o767// octal o It can be in both case
Properties and methods
parseInt() Convert to an integer
parseFloat() Convert to floating point number
isNaN() Judge whether it's a number
isFinite() Judge if it's a finite number
isInteger() Is it an integer // Integer returns true
Mathematical expansion
trunc() Remove the decimal part of a number
sign() Judge whether a number is a positive number 、 negative 、 It's still zero
return +1 Positive numbers return -1 negative
return +0 Positive zero return -0 Negative zero
return NaN Other values
cbrt() Calculate the cube root of a number
imul() Returns the product of two numbers , Include a plus or minus sign
hypot() Returns the square root of the sum of squares of parameters
signbit() Judge positive and negative numbers , Returns a Boolean value , Returns a negative number true
console.log(Math.signbit(-5))//true
console.log(Math.signbit(5))//false
console.log(Math.signbit(+0))//false
console.log(Math.signbit(-0))//true
console.log(Math.signbit("add"))//flase
Index of operation :2**3// by 8,2 multiply 3 All over =>2*2*2
边栏推荐
- Suanli & NFT trading platform f3 The exclusive NFT project of XYZ, hash eagle, will be grandly launched
- Page 112 machine learning - review of fundamentals of mathematics pptx
- oracle数据库常用的函数总结
- [proteus simulation] 51 MCU +ds1302+lcd1602 display
- JS functions
- The best screenshot tool in the world, color absorption tool snipaste
- golang项目依赖管理工具go vendor,go mod
- sigmoid函数sigmoid求导
- Rust, le meilleur choix pour un programmeur de démarrer une entreprise?
- API encapsulation of uniapp applet
猜你喜欢

Solving error: creating window glfw error: glew initialization error: missing GL version

Windows下MySQL的安装和删除

分享自己平時使用的socket多客戶端通信的代碼技術點和軟件使用

As a software testing engineer, how do you think to ensure software quality?

Today in history: Netease was founded; The first consumer electronics exhibition was held; The first webcast in the world

Kubernetes cluster construction of multiple ECS

还没弄明白微服务数据架构事务管理+ACID+一致性+CAP+BASE理论吗,看完彻底解决疑惑

数据采集系统网关采集工厂效率

112页机器学习-数学基础回顾.pptx

Getting started with numpy Library
随机推荐
Turtlebot+lms111+gmapping practice
To make pytorch faster, you need to master these 17 methods
DE2-115 FPGA开发板的VGA显示
One time summary: 64 common terms for data analysis!
golang项目依赖管理工具go vendor,go mod
Mysql database compressed backup_ Summary of MySQL backup compression and database recovery methods
Untiy force refresh UI
使用调试工具调试博图TCP连接所遇到的问题
Getting started with shell variables
Shell operator
关于STM32使用LAN8720A插拔网线重连
合宙Air32F103CBT6开发板上手报告
Is it safe to open an account with tongdaxin stock?
Where can the brightness of win7 display screen be adjusted
BACnet gateway bl103 for building automation
Les neuf caractéristiques de la parole et les neuf temps en anglais
Stream竟然还有应用进阶学习?作为程序员的你知道吗
Getting started with numpy Library
一次性总结:64个数据分析常用术语!
Is it safe for Guosen Securities to open an account?