Google News
logo
JavaScript - Interview Questions
If you need to calculate the Fibonacci series in JS, what will you do?
Fibonacci series is a pattern in which each given value is the sum of the previous two, and it starts with 0,1.
 
Method :
 
* use function fib(n),
* Declare var a=0 and b=1
* Use this condition (var i=0; i<n; i++)
* Use var temp = a+b;
* Next make a=b
* And b=temp;
* }
* Return a;

The series will come like 0,1,1,2,3,5…
Advertisement