Generators
In this lesson you’ll learn all about generators and what to do with them.
What is a generator? #
A generator function is a function that we can start and stop, for an indefinite amount of time. And also restart with the possibility of passing additional data at a later point in time.
To create a generator function we write like this:
Let’s have a look at the code piece by piece:
- we declared the function using
function* - we used the keyword
yieldbefore our content - we start our function using
.next() - the last time we call
.next()we receive and empty object and we get