yield generator javascript code example
Example 1: javascript yield
function* foo(index) {
while (index < 2) {
yield index;
index++;
}
}
const iterator = foo(0);
console.log(iterator.next().value);
// expected output: 0
console.log(iterator.next().value);
// expected output: 1
Example 2: function generator js
function* name([param[, param[, ... param]]]) {
statements
}