Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
解构赋值包含数组解构、对象解构、函数解构赋值
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>数组解构</title>
</head>
<body></body>
<script>
// 数组解构
let [name, age] = ["张峰", "33岁"];
console.log(name, age);
//迭代更新
[name, age] = ["老王", "44岁"];
console.log(name, age);
//参数不足添加默认值,参数过多,归并参数,用...
[a, b, c, d, e, ...f] = [1, 2, 4, 5, 6, 7, 8, 9];
console.log(a, b, c, d, e, f);
// 对象解构不用let时,等号左边禁止出现大括号,必须使用大括号时
// 用括号包住转为表达式
({ name, age } = { name: "张峰", age: "33岁" });
console.log(name, age);
// 函数解构传参
function getUser({ name, age }) {
console.log(name, age);
}
getUser({ name: "老吴", age: "66岁" });
</script>
</html>
下一篇写DOM