变量的解构赋值
ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构
let [a, b, c] = [1, 2, 3];
相当于
let a = 1;
let b = 2;
let c = 3;
变量也可以与对象之间解构
let [name]={name:'丁小柒'}; //name='丁小柒'
解构是按顺序匹配,如果匹配不到就会默认为解构失败,返回值是undefind
匹配时保证左右的类型一样,比如,
let []=[];//数组
let {}={} //对象
字符串的拓展
字符串的遍历接口for...of
循环遍历
for (let name of 'ding') {
console.log(name)
}
// "d"
// "i"
// "n"
// "q"
模版字符串
使用${}来来将变量可以直接写在字符串内,模版字符串要写在反引号里,也就是esc按钮下面的那个
let name="丁小柒";
let tell =`my name is ${name}`;
console.log(tell); //my name is 丁小柒