O'Reilly logo

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond by JD Isaacks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lesson 18. Generator functions

After reading lesson 18, you will

  • Know how to define generator functions
  • Know how to yield values from generator functions
  • Understand the generator function lifecycle

Generator functions are one of the harder things to comprehend among all the recent additions to JavaScript. They introduce a new form of code execution and processing that most JavaScript developers haven’t seen before. Generators aren’t new concepts, though—they’re already part of Python, C#, and other languages. This lesson is only meant to be a gentle introduction to the topic.

You’ll see how good generators are at creating lists, but that isn’t all generators are good for. That would be like saying objects are only useful for storing key/value ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required