1. iterable


iterable이란 자료를 반복할 수 있는 객체이다.

우리가 쓰는 배열도 iterable 객체다.

let arr = [1,2,3]
for(const a of arr) console.log (a) // 정상작동 1,2,3

arr[Symbol.iterator] = null; // 이렇게 하면 순회가 되지 않는다
for(const a of arr) console.log (a) // Uncaught TypeError: arr is not iterable

만일 이 배열에 iterable 표식을 강제로 null을 할당해 없애버리면 멀쩡한 배열임에도 for… of로 순회할 수 없다.

2. iterable과 iterator


2-1) iterable protocol/iterator protocol

이터러블을 [for… of], [전개 연산자], [비구조화]..등, 이터러블이나 이터레이터 프로토콜을 따라는 연산자들과 함께 동작하도록 하는 약속된 규약을 의미함

이터러블 === 이터러블 규약을 따르는 객체

2-2) iterable

이터레이터를 리턴하는 [Symbol.iterator]() 메서드를 가진 객체

배열의 경우 Array.prototype의 Symbol.iterator를 상속받기 때문에 이터러블 (문자열도 마찬가지다)