How to calculate Fibonacci numbers in JavaScript?


Posted On: Oct 31, 2022


Process of calculating Fibonacci Series in JavaScript

Fibonacci numbers are a sequence of numbers where each value is the sum of the previous two, starting with 0 and 1. The first few values are 0, 1, 1, 2, 3, 5, 8, 13 ,…,

function fib(n) {
	var a=0, b=1;
	for (var i=0; i < n; i++) {
		var temp = a+b; 
		a = b;
		b = temp;
	return a;

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    JavaScript Interview Questions

    Explain what is Javascript?

    Javascript Javascript is an object-oriented computer programming language commonly used to create interactive effects wi..