var = "hello world";
左边是变量名,右边可以是任意的数据类型。
数组的解构赋值
可以为多个变量赋值,例如:
var = 1;
var = 2;var = 3;let [ , , ] = [1, 2, 3];
(1)嵌套数组的解构
let [ , [[ ], ]] = [1, [[2], 3]];
console.log( ); console.log( );console.log( ); let [ , , ] = [1, 2, 3];console.log( );let [ , , ] = [1, 2, 3];console.log( );console.log( );(2)数组解构的默认值
var [ , ] = [];
.log( ); // undefined.log( ); // undefined// 有默认值var [ = 1, = 2] = [];console.log( ); console.log( );var [ = 1, = 2] = [3, 4];console.log( );console.log( );(3)对象的解构赋值
var { : , : } = { : "zhangsan", : 20 };
console.log( );console.log( );(4)嵌套对象的解构
var = {
: ["张三", { : "二狗子" }]}// 属性名跟属性值的变量名不相同时var { : [ , { : }] } = ;console.log( ); console.log( ); // 属性名跟属性值的变量名相同时var { : [ , { }] } = ;console.log( );console.log( );