Calling an iterator’s next() method advances it and returns an iterator result with value and done properties. On a generator, each call runs until the generator yields or returns; an uncaught error is thrown from the call. section 8.3.2 section 8.3.1
Read the result according to how iteration proceeds:
- After yield, value holds the yielded value and done is false. section 8.3.2
- After return or reaching the end, done is true and value holds the return value, or undefined. section 8.3.2
Listing 8.9 Looping through an array using its iterator
const numbers = [1, 2, 3];
const iterator = numbers[Symbol.iterator](); #A
let iteratorResult = iterator.next(); #B
while (!iteratorResult.done) { #C
console.log(iteratorResult.value); #D
iteratorResult = iterator.next(); #E
}
An array iterator makes the protocol visible: call next(), use value while done is false, then call next() again. section 8.3.1
Generator calls can also pass a value back into a suspended generator: the argument to a later next() call becomes the value of the preceding yield expression. section 8.3.2





