1、let,const

let: 引入了块级作用域的变量声明,相比于var的函数作用域或全局作用域,let提供了更细粒度的作用域控制。
const: 用于声明常量,一旦赋值后不能更改。和let一样,const也是块级作用域。

2、箭头函数

const str=’string’;

const str1=String(‘string’)

const str2=new String(‘string’)

3、模板字符串

4、默认参数

调用没有提供值,使用默认值

5、解构赋值

解构赋值是ES6的一个非常有用的特性,它允许你从数组或对象中提取值,然后将这些值赋给变量,使得数据访问更加方便。下面是一些使用解构赋值的例子:

1.从对象解构:

1
2
3
4
5
6
7
8
9
10
11
12
const person = {
name: 'John Doe',
age: 30,
location: 'New York'
};

// 从对象中解构并赋值给新变量
const { name, age } = person;

console.log(name); // 输出 "John Doe"
console.log(age); // 输出 30

2.从数组解构:

1
2
3
4
5
6
7
const colors = ['Red', 'Green', 'Blue'];

const [firstColor, secondColor] = colors;

console.log(firstColor); // 输出 "Red"
console.log(secondColor); // 输出 "Green"

3.函数参数解构

1
2
3
4
5
6
7
8
9
10
function displayUser({name, age}) {
console.log(`Name: ${name}, Age: ${age}`);
}

const user = {
name: 'Jane Doe',
age: 25
};

displayUser(user); // 输出 "Name: Jane Doe, Age: 25"

4、默认值

1
2
3
4
5
const { name, age, gender = 'Male' } = { name: 'Bob', age: 34 };

console.log(name); // 输出 "Bob"
console.log(age); // 输出 34
console.log(gender); // 输出 "Male"(默认值)

5.剩余参数和扩展运算符

剩余参数(...)可以用来在解构数组或对象时收集剩余的值。

1
2
3
4
5
6
7
8
const { name, ...rest } = {
name: 'Alice',
age: 28,
job: 'Developer'
};

console.log(name); // 输出 "Alice"
console.log(rest); // 输出 { age: 28, job: 'Developer' }

6、扩展运算符(…)

可以用来复制数组、合并数组、函数调用等,

复制:

1
2
const arr1=[1,2,3];
const arr2=[...arr1];arr2=[1,2,3]

合并:

1
2
3
4
const arr1=[1,2,3];
const arr2=[4,5,6];

const arr=[...arr1,...arr2];//arr=[1,2,3,4,5,6]

将数组元素作为函数的多个参数传递:

1
2
3
4
5
function sum(a,b,c){
return a+b+c;
}
const numbers=[1,2,3];
sum(...numbers);//6

将字符串转换为数组:

1
2
const str='hello';
const str1=[...str];//['h','e','l','l','o']

7、Promise和异步编程

为了解决异步操作回调地狱的问题,使得异步的代码写法更加清晰,一共有三个状态:

  • Pending(等待中):初始状态,既不是成功,也不是失败状态。

  • Fulfilled(已成功):意味着操作成功完成。

  • Rejected(已失败):意味着操作失败。

8、Module

9、新的数据结构和API

10、类class