An iterator result is the object returned by next(). Its value property carries the step’s value, while done indicates whether iteration has finished. section 8.3.1
For generators, yield produces { value, done: false }; return produces { value, done: true }. If the generator throws, the error comes from the next() call. 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
}
Repeated next() calls expose the iterator results that for…of normally handles for you. section 8.3.1
Async iterators use the same result shape, but next() returns a promise that fulfills with the result. section 8.3.3
