Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

generators in javascript

//- With a generator function, values are not evaluated 
//until they are needed.
//- Therefore a generator allows us to define a potentially
//infinite data structure.

function* generator() {
  yield 1;
  yield 2;
  yield 3;
}

const gen = generator(); // "Generator { }"

console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // 3
 
PREVIOUS NEXT
Tagged: #generators #javascript
ADD COMMENT
Topic
Name
6+4 =