Skip to content
Lesson 11 of 15

Step 1 of 5 · Reading · ~1 min

Learn

Generators 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.

Up nextRegular ExpressionsGenerators and Regex

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…