[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/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 9.

yield (function* generator ) .

In this article

js
[rv] = yield [expression];
expression

. , undefined .

rv

, optional value next() .

yield yield [expression] caller . return .

yield value done IteratorResult . value yield (expression) , done (Boolean) .

yield , next() . next() :

  • yield . next() , yield .
  • throw . , .
  • ; , IteratorResult caller undefined done true .
  • return . , IteratorResult caller return done true .

optional value next() , optional value yield .

generator , yield, Generator.prototype.next() .

.

js
function* foo() {
  var index = 0;
  while (index <= 2)
    // when index reaches 3,
    // yield's done will be true
    // and its value will be undefined;
    yield index++;
}

, iterator .

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

See also


Web Proxy Viewer  |  New URL  |  Original Page