数组解构
let arr = [1, 2, 3]
let [a, b, c] = arr
//a = 1, b = 2, c = 3, 取出数组中的数据赋给对应位置的变量
对象解构
let person = {
name: zhangsan,
age: 18
}
let {name} = person
//从person对象中取出name属性的值,并赋给name变量;这是要取出的属性名和要赋值的变量名相同的情况,如果要把name属性取出赋给NAME呢?
let {name: NAME} = person
字符串模板
字符串模板相当于加强的字符串,用反引号``,除了作为普通字符串,还可以用来定义多行字符串,在字符串中加入变量和表达式,调用函数
let name = "zhangsan"
let age = 18
function hello(){
return "hi, you guys!"
}
let introduce = `${hello()}i'm ${name} and i'm ${age+1} years old`