function * fibonaciSeries ( ) { let first = 0 ; let second = 0 ; let third = 0 ; let i = 0 ; while ( true ) { if (i== 0 || i== 1 ) { first = 1 ; second = 1 ; third = 1 ; } else { first = second; second = third; third = first + second; } i+= 1 ; yield third; } } fibo = fibonaciSeries(); for ( let i= 0 ; i< 10 ; i++) { val = fibo.next(); console .log(val.value); } You can call infinite loop or call .next() as much you want