Language concepts

Generator object

Try the free JavaScript compiler

Stateful synchronous iterable iterator produced by a generator function. Supports next, return and throw, and cannot restart after completion.

Formal Syntax & Structure

javascript syntaxjavascript
const iterator = generatorFunction()

Working Example

Example Snippetjavascript
function* g(){yield 2;}const it=g();console.log(it[Symbol.iterator]()===it);
JavaScript Reference