# How to calculate Fibonacci numbers in JavaScript?

devquora

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

Never Miss an Articles from us.

## Related Questions

#### Explain what is Javascript?

JavaScript, a dynamic, client-side language, is crucial in modern web development, working alongside HTML and CSS. Its manipulation of the Document Object Model (DOM) enables dynamic content and inter..

#### What close() does in Javascript?

In JavaScript, the close() method is employed to securely close the current window. To ensure its association with the window object rather than another JavaScript object, employ window.close(). This ..

#### What is the difference between let and var?

Both var and let are utilized for variable/method declaration in JavaScript. The crucial disparity lies in their scope: var is function-scoped, meaning it's accessible throughout the function it's def..