January 2020
Intermediate to advanced
548 pages
13h 36m
English
The very last type of function definition style we will cover is the very powerful generator function. Broadly, generators are used to supply and control the iteration behavior for a sequence of one or more, or even infinite, items.
Generator functions in JavaScript are specified with an asterisk following the function keyword:
function* myGenerator() {...}
When called, they will return a generator object, which uniquely conforms to both the iterable protocol and the iterator protocol, meaning that they can be iterated over themselves or can serve as an object's iteration logic.
Read now
Unlock full access