Iterables and Iterators

introduction to Iterables and Iterators and their behavior in Javascript

Now that we have introduced the for...of loop and symbols, we can comfortably talk about iterators.

It is worth for you to learn about iterators, especially if you like lazy evaluation, or you want to be able to describe infinite sequences. Understanding of iterators also helps you understand generators, promises, sets, and maps better.

Once we cover the fundamentals of iterators, we will use our knowledge to understand how generators work.

ES6 comes with the iterable protocol. The protocol defines the iterating behavior of JavaScript objects.

An iterable object has an iterator method with the key Symbol.iterator. This method returns an iterator object.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.