JavaScriptAdvanced#es6

What are generators and iterators?

An iterator exposes next() returning { value, done }. A generator function (function*) creates one automatically and can pause at each yield, which suits lazy sequences and custom iteration.

Example
function* ids() { let i = 1; while (true) yield i++; }
const g = ids();
g.next().value; // 1
g.next().value; // 2

Related Questions

1
JavaScriptIntermediate#es6#modules

What is the difference between a module and a script? (import/export)

Open
2
JavaScriptIntermediate#objects

What is the difference between Object.freeze and const?

Open
3
JavaScriptBeginner#numbers

What is NaN and how do you check for it?

Open