Open wangbinze opened 3 years ago
语句通常使用一或多个关键字完成既定的任务。也称流控制语句。
if (condition1) statement1 else if (condition2) statement2 else statement3
cindition可以是任何表达式,但都会自动调用 Boloean() 把值转为为布尔值。
let i = 0;
do {
i += 2;
} while (i < 10);
let i = 0;
while (i < 10) {
i += 2;
}
let count = 10;
for (let i = 0; i < count; i++) {
console.log(i);
}
for (const propName in window) {
document.write(propName);
}
for (const el of [2,4,6,8]) {
document.write(el);
}
start: for (let i = 0; i < count; i++) { //start 就是一个标签
console.log(i);
}
switch (expression) {
case value1:
statement;
break;
case value2:
statement;
break;
default:
statement;
}
题目:JS中常用的语句有哪些?