Control Flow
If
if (cond1) {
// ...
} else if (cond2) {
// ...
} else {
// ...
}Switch
switch (x) {
case 0: // switch-case uses a === match
// ...
break;
case 1:
case 2: // in JS, the code block can be shared between cases like C
// ...
break;
// ...
default:
// ...
}For
For-in
For-in loops over properties of an object.
事实上 for - in 的迭代次序在应用于数组时并不一定依赖数组本身的索引顺序,所以如果要遍历一个数组,建议采用传统 for 或者
Array.prototype.forEach或者下文的 for - of 。
For-of
For-of loops over values of an iterable object.
Reference
Last updated
Was this helpful?