Reading — step 1 of 5
Learn
~1 min readGenerators and Regex
Anything with a [Symbol.iterator]() method is iterable — you can for...of it, spread it, destructure it.
Generators are functions that return iterators. They use function* and yield:
js
yield pauses the function. Calling .next() on the iterator resumes it.
Generators shine for infinite sequences (lazy evaluation):
js
Also useful for tree traversal, parsing, custom iteration patterns.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…