1.两种JavaScript语句
- 普通语句
- 声明型语句
2.普通语句
2-1 switch语句
switch(num) {
case 1:
print(1);
case 2:
print 2;
case 3:
print 3;
}
2-2 for in 循环
for in 循环枚举对象的属性,体现了属性的enumerable特征。
let o = { a: 10, b: 20}
Object.defineProperty(o, "c", {enumerable:false, value:30})
for(let p in o)
console.log(p); // a b
我们给对象o添加了不可枚举的属性c,使用for in 循环枚举它的属性,只能得到a b。
2-3 for of 循环
for of循环是非常棒的语法特性,可以用于数组。
for(let e of [1, 2, 3, 4, 5])
console.log(e); // 1 2 3 4 5
2-4 try语句和 throw 语句
try {
throw new Error("error");
} catch(e) {
console.log(e);
} finally {
console.log("finally");
}