jskatas.org Continuously Learn JavaScript. Your Way.

Generator: yield expressions

The yield keyword is used to pause and resume a generator function

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

Generator - yield is used to pause and resume a generator function

  • converting a generator to an array (using Array.from) resumes the generator until all values are received

after the first generator.next() call

  • the value is "hello"
  • and done is false

after the second next() call

  • value is "world"
  • and done is still false

after stepping past the last element, calling next() that often

  • done property equals true, since there is nothing more to iterator over

Links

Describing the `yield` keyword.