Print Fibonacci sequence using 2 variables | Simple Javascript Program to print Fibonacci sequence ; Driver code
function fib ( n ) { let a = 0 , b = 1 , c ; if ( n >= 0 ) document . write ( a + " " ) ; if ( n >= 1 ) document . write ( b + " " ) ; for ( let i = 2 ; i <= n ; i ++ ) { c = a + b ; document . write ( c + " " ) ; a = b ; b = c ; } } fib ( 9 ) ;