JavaScript: Generator function example

Table of contents

No heading

No headings in the article.

function* gen()  
{  
  yield 100;  
  let a = 100
  a = a + 1
  yield a;
  a = 200
  yield a * 2;
}

// Calling the Generator Function  
var mygen = gen();  
console.log(mygen.next().value);
console.log(mygen.next().value);
console.log(mygen.next().value);
Output:
100
101
400

Execute above code here