Study Guide: JavaScript->Generators

Generators are part of the ECMAScript 6 language specification. Firefox has supported the ECMAScript 6 compliant syntax for generators since 2013-12-10.[1] Node.js (server-side JavaScript) also has supported ES6 generator syntax[2] since 2013-05-15.[]


function* vehicle{
  var index = 0;
  while (index < 4)
    yield index++;

var firetruck = vehicle;
var car = vehicle;

console.log(; // 0
console.log(; // 1
console.log(; // 0
console.log(; // 2
console.log(; // 1
console.log(; // 3
console.log(; // undefined

The function* keyword creates a generator function.[3]

Further reading

(FIXME: Say a few more words about generators. Perhaps use some or all of the following as references:

"Generators in Node.js: Common Misconceptions and Three Good Use Cases". "Coroutines no, generators yes. Why coroutines won't work on the Web". "What Is This Thing Called Generators?". "callbacks vs generators vs coroutines".)


  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.



Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.

Manage research, learning and skills at Create an account using LinkedIn to manage and organize your omni-channel knowledge. is like a shopping cart for information -- helping you to save, discuss and share.

  Contact Us