Mid JavaScript

What are generators?

Generators are special functions that can pause and resume execution using the

function* syntax and yield.

Example:

function* counter() {

yield 1;

yield 2;

const gen = counter();

console.log(gen.next().value); // 1

More from JavaScript Tutorial

All questions for this course