0
What is the difference between an iterator and a generator, and when would you use one over The other?
2 odpowiedzi
0
In essence, Ive learnt that the difference between n iterator and a generator, is:
that the generator is simply a function with * affixed.
it uses the yield keyword to iterate over its members.
it can also call other generators with *
you can control it manually with the .next() method.
the iterator is created with [Symbol.iterator]()
it can also be iterated over with the next().value methods
iterators and generators are useful in asynchronous programming