Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:
let site = "PHP中文网";
site = `${site}(www.php.cn)`;
输出结果为: PHP 中文网(www.php.cn)
解构要求等号两边类型一致
. 对象解构
({name,age}={name:”jack”,age:28});
<script>
//插值模式拼接字符串
let site = "PHP中文网";
site = `${site}(www.php.cn)`;
console.log(site);
//解构对象, 把对象的值赋给左边的变量
({ name, age } = { name: "jack", age: 30 });
console.log(name);
console.log(age);
//解构数组,用变量接收到了数组中的值
let arr = ["red", "green", "blue"];
[c1, c2, c3] = arr;
console.log(c1);
console.log(c2);
console.log(c3);
//流控
//1.分支判断if, 在判断时, 并且&&, 或||
if (1 > 2) {
console.log("这是不可能的");
} else {
console.log("1大于2是假");
}
//2.多分支switch case break
switch (6) {
case 5:
console.log("值为5时进入");
break;
case 6:
console.log("值为6时进入");
break;
}
//3.while,先判断再执行,下面示例不执行
let i = 4;
while (i < 3) {
console.log(i);
i++;
}
//4.do while 先执行再判断,输出4
do {
console.log(i);
i++;
} while (i < 3);
//5.for(){} 示例如下
for (let i = 0; i < 3; i++) {
console.log(i);
}
//6.for in 能循环取对象, 也能遍历数组
let obj1 = { name: "jack", age: 20 };
//依次输出name和age的值
for (let k in obj1) {
console.log(obj1[k]);
}
//7.for of 在ES6中所有集合遍历都统一了,集合要求是迭代类型集合
//不能遍历自定义对象,因为自定义对象没有迭代属性
//手可加了迭代属性后就可以遍历了
//示例遍历数组,输出red green blue
for (let v of arr) {
console.log(v);
}
</script>