- 声明多个变量并解构赋值
let [a, b, c] = [1, 2, 3];
let [a, ...b] = [1, 2, 3]
let [a, b, c] = 'hel';
let { a, b } = { a: 'a', b: 'b' }
let {a, ...b}={a: 10, b: 20, c: 30};
- 简写
const age = 12;
const name = "Amy";
const person = {age, name};
let person={
getName({a}){
console.log(a);
};
}
- 函数
- 箭头函数 : (a,b)=>{},单变量简写 a=>{}
- 函数参数: …args,用来代替arguments
- …运算符
function a(...param){
console.log(param);
}
let [a, ...b] = [1, 2, 3]
let {a, ...b}={a: 10, b: 20, c: 30};
let arr1 = [1, 2];
let arr2 = [3, 4];
let arr = [...arr1, ...arr2];
let age = {age: 15};
let name = {name: "Amy"};
let person = {...age, ...name};
let fun= function(a,b,c){}
let param=[1,2,3]
fun(...param)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 默认值
function f(b,c=1){
console.log(c)
};
f(2)
let {a=1,b}={b:2};
let [a,b=2]=[1];
- 引入了Map和Set对象
- n次方操作符:**,eg. 2**3=8
- Array.includes:是否包含某元素
- async、await
async function a(){
await ajax();
await ajax2();
}
- flat和flatMap
[1,2,[3,4]].flat(1)
flatMap是map和flat的结合,下面的两个操作是等价的:arr.flatMap(func)
arr.map(func).flat(1)
- import () 方法:动态导入
- String.prototype.replaceAll
const str = "hello world";
str.replace(/o/g, "a")
str.replaceAll("o", "a")
- ?? 运算符
let a=b||'1'
let a=b??'1'
- ??= 空值赋值运算
let a=2;
a??=1
console.log(a)
- ?. 对象为空时,获取其属性不报错,而获取到undefined值
let a;
let d=a?.b