coderef

GeneratorsBaseline · Widely available

Generator functions (function*) create iterators that return multiple values, one after another, on-demand.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Sep 20, 2016. Widely available since Mar 20, 2019.

Browser support

DesktopChrome
1–38Not supported
39+Supportedsince Nov 18, 2014
Current: 155
Edge
12–12Not supported
13+Supportedsince Nov 12, 2015
Current: 154
Firefox
1–25Not supported
26+Supportedsince Dec 10, 2013
Current: 157
Safari
1–9.1Not supported
10+Supportedsince Sep 20, 2016
Current: 27
MobileChrome Android
18–38Not supported
39+Supportedsince Nov 12, 2014
Current: 155
Firefox Android
4–25Not supported
26+Supportedsince Dec 10, 2013
Current: 157
Safari iOS
1–9.3Not supported
10+Supportedsince Sep 13, 2016
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: Generator.

Feature detection

JS · check before using
// Syntax can't be tested with an if-statement — an unsupported
// browser fails to parse the whole script. Either transpile for older
// targets (e.g. Babel/TypeScript/esbuild), or probe in isolation:
let supported = true;
try {
  new Function("/* code that uses the syntax */");
} catch {
  supported = false;
}

This is a language syntax feature.

Sub-features

Support for each part of the feature (14). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Generator39132610392610
Generator.next39132610392610
Generator.return50133810503810
Generator.throw39132610392610
GeneratorFunction39132610392610
GeneratorFunction.GeneratorFunction39132610392610
generator_function49122610492610
generator_function.trailing_comma58795210585210
yield39122610392610
yield_star39122710392710
generator_function39132610392610
generator_function.IteratorResult_object49132910492910
generator_function.not_constructable_with_new50134310504310
generator_function.trailing_comma_in_parameters58145210585210