js generator
function* fib() { let previous = 0; let current = 1; while (true) { yield current; const next = current + previous; previous = current; current = next; } } /* output: 1 1 2 3 5 8*/ const g = fib(); console.log(g.next().value); console.log(g.next().value); console.log(g.next().value); console.log(g.next().value); console.log(g.next().value); console.log(g.next().value);