| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/yield | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2016 ..
yield - (function* legacy generator function).
function* foo(index) {
while (index < 2) {
yield index;
index++;
}
}
const iterator = foo(0);
console.log(iterator.next().value);
// Expected output: 0
console.log(iterator.next().value);
// Expected output: 1
[rv] = yield [[]];
. , undefined.
rv , next() , .
yield - , yield. return -.
yield , value done. , value yield, done , -.
yield, - , next() -. .
- :
function* foo() {
var index = 0;
while (index <= 2)
// 2, done yield true, value undefined;
yield index++;
}
- , :
var iterator = foo();
console.log(iterator.next()); // { value:0, done:false }
console.log(iterator.next()); // { value:1, done:false }
console.log(iterator.next()); // { value:2, done:false }
console.log(iterator.next()); // { value:undefined, done:true }
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # prod-YieldExpression |
This page was last modified on 17 . 2025 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |