흐름 제어
- 조건문과 반복문으로 흐름을 제어함
- 아래 구문을 다룸
- return, break, continue, throw, if...else, switch, try...catch
- for, do...while, while, for...in, for...of
- C언어, 파이썬과 유사함.
for...in, for...of
- for in 구문은 파이썬의
for element in target.__dict__["keys"]
구문과 비슷하다.
- index(in)를 순회한다고 생각하면 된다. 객체의 모든 key를 반환한다.
- for of 구문은 파이썬의
for element in elements
구문과 비슷하다. 반복 가능한 객체에서 하나씩 값을 순환한다.
let array = [1, 2, 3, 4, 5];
array.foo = 'bar';
for (const item of array) {
console.log(item);
}
for (const item in array) {
console.log(item);
}