/*变量的解构赋值*/
var a = 1;
var b = 2;
var c = 3;
var a = 1, b = 2, c = 3;
// 数组的结构赋值
let [a,b,c] = [1,2,3]; 1 2 3
let [a,b,c] = [,123,]; undefined 123 undefined
let [a=111, b, c] = [,123,] 111 123 undefined
console.log(a, b, c);
// 对象的结构赋值
let {foo,bar} = {foo: 'hello',bar: 'hi'}; hello hi
let {foo,bar} = {bar: 'hi',foo: 'hello'}; hello hi
console.log(foo,bar);
// 对象属性别名(如果有了别名,那么原来的名字就无效le)
let {foo:abc,bar} = {bar : 'hi',foo : 'nihao'};
console.log(foo,bar);报错
console.log(abc,bar);nihao hi
// 对象的结构赋值指定默认值
let{foo:abc='hello',bar} = {bar : 'hi'};
console.log(abc,bar); hello hi
let {cos,sin,random} = Math;
console.log(typeof cos);
console.log(typeof sin);
console.log(typeof random);
// ----------------------------
// 字符串的结构赋值
// 数组
let [a, b, c, d, e] = "hello";
console.log(a,b,c,d,e); h e l l o
console.log(a,b,c,d); h e l l
console.log("hello".length);5
// 对象
let {length} = "h1";
console.log(length);2