Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
The yield* operator can be used within generator (sync or async) functions to delegate to another iterable object, such as a Generator. Inside async generator functions, it can additionally be used to delegate to another async iterable object, such as an AsyncGenerator.
An iterable object.
Returns the value returned by that iterator when it's closed (when done is true).
The yield* expression iterates over the operand and yields each value returned by it. It delegates iteration of the current generator to an underlying iterator — which we will refer to as "generator" and "iterator", respectively. yield* first gets the iterator from the operand by calling the latter's [Symbol.iterator]() method. Then, each time the next() method of the generator is called, yield* calls the iterator's next() method, passing the argument received by the generator's next() method (always undefined for the first call), and yielding the same result object as what's returned from the iterator's next() method. If the iterator result has done: true, then the yield* expression stops executing and returns the value of that result.
The yield* operator forwards the current generator's throw() and return() methods to the underlying iterator as well. If the current generator is prematurely closed through one of these methods, the underlying iterator will be notified. If the generator's throw()/return() method is called, the throw()/return() method of the underlying iterator is called with the same argument. The return value of throw()/return() is handled like the next() method's result, and if the method throws, the exception is propagated from the yield* expression.
If the underlying iterator doesn't have a return() method, the yield* expression turns into a return statement, just like calling return() on a suspended yield expression.
If the underlying iterator doesn't have a throw() method, this causes yield* to throw a TypeError – but before throwing the error, the underlying iterator's return() method is called if one exists.
In following code, values yielded by g1() are returned from next() calls just like those which are yielded by g2().
Besides generator objects, yield* can also yield other kinds of iterables (e.g., arrays, strings, or arguments objects).
yield* is an expression, not a statement, so it evaluates to a value.
The next(), throw(), and return() methods of the current generator are all forwarded to the underlying iterator.
If the return()/throw() method of the underlying iterator returns done: false, the current generator continues executing and yield* continues to delegate to the underlying iterator.
If the underlying iterator doesn't have a throw() method and the generator's throw() is called, yield* throws an error.
| ECMAScript® 2027 Language Specification # sec-generator-function-definitions-runtime-semantics-evaluation |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.