<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
/*
注意点:
对象的解构赋值和数组的解构赋值 除了符号不一样, 其它的一模一样
数组解构使用[]
对象解构使用{}
*/
//左边的格式与右边的格式要一样。
/*let [a,b,c]=[6,66,666];
console.log(a,b,c);*/
//个数可以不一样.
/*let [a,b]=[1,11,111];
console.log(a,b);
*/
/*let [a,b,c,d]=[1,11,111];
console.log(a,b,c,d);
*/
// 3.在数组的解构赋值中,如果右边少于左边, 我们可以给左边指定默认值
/*let [a,b,c=555]=[1,3];
console.log(a,b,c);
*/
let obj={
name:"cyg",
age:666
};
/*let name=obj.name;
let age=obj.age;*/
//let {name,age}=obj;
/* let {name,age}={name:"cyg",age:666};
console.log(name,age);*/
/*let {name} = {name: "lnj",age: 34};
console.log(name); */
/*let {name, age, height} = {name: "lnj",age: 34};
console.log(name, age, height); */
/*let {name, age, height = 1.80} = {name: "lnj",age: 34};
console.log(name, age, height);*/
// 注意点: 在对象解构赋值中, 左边的变量名称必须和对象的属性名称一致, 才能解构出数据
//let {a, b} = {name: "lnj",age: 34};
//console.log(a, b); // undefined undefined
let {age} = {name: "lnj",age: 34};
console.log(age); // 34
</script>
</body>
</html>