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: 155Edge
12–12Not supported
13+Supportedsince Nov 12, 2015
Current: 154Firefox
1–25Not supported
26+Supportedsince Dec 10, 2013
Current: 157Safari
1–9.1Not supported
10+Supportedsince Sep 20, 2016
Current: 27MobileChrome Android
18–38Not supported
39+Supportedsince Nov 12, 2014
Current: 155Firefox Android
4–25Not supported
26+Supportedsince Dec 10, 2013
Current: 157Safari iOS
1–9.3Not supported
10+Supportedsince Sep 13, 2016
Current: 27How 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-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| Generator | 39 | 13 | 26 | 10 | 39 | 26 | 10 |
| Generator.next | 39 | 13 | 26 | 10 | 39 | 26 | 10 |
| Generator.return | 50 | 13 | 38 | 10 | 50 | 38 | 10 |
| Generator.throw | 39 | 13 | 26 | 10 | 39 | 26 | 10 |
| GeneratorFunction | 39 | 13 | 26 | 10 | 39 | 26 | 10 |
| GeneratorFunction.GeneratorFunction | 39 | 13 | 26 | 10 | 39 | 26 | 10 |
| generator_function | 49 | 12 | 26 | 10 | 49 | 26 | 10 |
| generator_function.trailing_comma | 58 | 79 | 52 | 10 | 58 | 52 | 10 |
| yield | 39 | 12 | 26 | 10 | 39 | 26 | 10 |
| yield_star | 39 | 12 | 27 | 10 | 39 | 27 | 10 |
| generator_function | 39 | 13 | 26 | 10 | 39 | 26 | 10 |
| generator_function.IteratorResult_object | 49 | 13 | 29 | 10 | 49 | 29 | 10 |
| generator_function.not_constructable_with_new | 50 | 13 | 43 | 10 | 50 | 43 | 10 |
| generator_function.trailing_comma_in_parameters | 58 | 14 | 52 | 10 | 58 | 52 | 10 |