JavaScript yield Operator
The yield operator pauses a generator function and hands a value back to the caller. yield* hands over every value of another iterable.
Description
The yield operator is used inside generator functions (function*). Each time it runs, the generator pauses and the value is returned from the caller's next() call as { value, done: false }. When next() is called again, the generator continues after the yield, and the argument passed to next() becomes the result of the yield expression.
yield* delegates to another iterable or generator, yielding each of its values in turn.
When a generator finishes with a return statement, its value appears as the final { value, done: true } result, but for...of and spread syntax ignore it. yield can only be used directly inside a generator function, not in a nested regular function or callback, which means you can't yield from inside a forEach().
Properties
- Operator
yield- Category
- Other
- Precedence
- 2 (1 is lowest, 18 is highest)
- Associativity
- right-to-left
Syntax
yield
yield expression
yield* iterableExample
Browser Support
The following information will show you the current browser support for the yield operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





