[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/yield [Back]  [Original]

yield - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

yield

Baseline Widely available

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).

In this article

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() -. .

- :

js
function* foo() {
  var index = 0;
  while (index <= 2)
    //   2, done  yield  true,  value undefined;
    yield index++;
}

- , :

js
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


Web Proxy Viewer  |  New URL  |  Original Page