JavaScript function* Statement
The function* declaration defines a generator function, which can pause with yield and produce a sequence of values one at a time.
Description
The function* declaration defines a generator function. Calling it doesn't run the body; it returns a Generator object. Each call to the generator's next() runs the body until the next yield, which produces a value and pauses. When the function returns, the generator is done.
Generators make it easy to create iterators, including infinite sequences, because values are only computed when they're asked for. They work directly with for...of, spread syntax and iterator helpers.
A generator can also receive values: the argument passed to next(value) becomes the result of the paused yield expression, which allows two-way communication. yield* delegates to another generator or iterable, yielding each of its values in turn. Generator functions can't be arrow functions, and they can't be used with new.
Syntax
function* name(params) {
yield value;
}Example
Browser Support
The following information will show you the current browser support for the function* statement. Hover over a browser icon to see the version that first introduced support for this statement.
Desktop





Tablets & Mobile





