Iterators and Generators
Processing each item in a collection is a very common operation, no matter the programming language. JavaScript is no exception and provides a number of ways to iterate over collections. The spectrum ranges from simple
for
loops to the more complexmap()
andfilter()
.Iterators and Generators bring the concept of iteration, build into the core of JavaScript and provide a mechanism for customizing the behavior of
for…of
loops.
Source: How JavaScript works: iterators + tips on gaining advanced control over generators, an article by Alexander Zlatkov.