Loading topic
Map, Set, spread, and destructuring.2 min readSymbol.iterator. In that chapter, an iterable was an object that can hand out an iterator. This chapter covers the iterator itself: the object that actually produc2 min readSymbol.iterator method, and that calling next() on an iterator returns { value, done }. It also assumes you have basic experience with arrays, Map, and Set. The chapter covers which built-in values follow 2 min readMap and Set.2 min read[Symbol.iterator]() method, and that method returns an iterator whose next() returns { value, done }. You should also be comfortable with classes and closures.2 min readfor...of and destructuring consume iterables.2 min readnext() method that returns { value, done }. It also assumes you are comfortable with functions and object methods.2 min readfunction* and yield, and that you can read the { value, done } results returned by next(). Here you will learn when the code inside a generator actually runs, and what happens once it finishes.2 min readyield and resumes on next().2 min readfunction* and yield. It also assumes you know that for...of and spread ignore a generator's return value. Here you will learn how one generator can hand control to another iterable, and what it gets back when that iterable finishes.2 min readyield and resume on next(), as covered in the chapter on generator execution. So far, values have flowed only out of a generator. A generator object has three methods that also send something in: next(value), throw(error), and `return(val2 min readfor...of calls an iterator's return() method on early exit, and how next(), throw(), and return() drive a generator from outside.2 min readnext() is called, and know that leaving a for...of early calls the iterator's return().2 min readmap and take were hand-written generator functions. Iterator helpers are built-in methods on Iterator.prototype, added in ES2025. They give you the same lazy pipeline2 min readasync/await.2 min readfor await...of and Symbol.asyncIterator from the previous chapter, plus generator functions and async/await. An async generator brings those ideas together. It is a function that can await a promise and also yield values, and it produces an async iterator au2 min read