The yield* keyword

The yield* keyword inside a generator function takes an iterable object as the expression and iterates it to yield its values. Here is an example to demonstrate this:

function* generator_function_1(){  yield 2;  yield 3;}function* generator_function_2(){ yield 1;  yield* generator_function_1();  yield* [4, 5];}const generator = generator_function_2();console.log(generator.next().value);console.log(generator.next().value);console.log(generator.next().value);console.log(generator.next().value);console.log(generator.next().value);console.log(generator.next().done);

The output is as follows:

12345true

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.