JavaScript Program to Find n-th Fibonacci Number Last Updated : 16 Feb, 2024 Comments Improve Suggest changes Like Article Like Report The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. The sequence goes as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. Given an integer n, the task is to find the n-th Fibonacci number. These are the following methods: Table of Content Recursive ApproachIterative ApproachDynamic Programming ApproachRecursive ApproachIn this method, the Fibonacci number is determined by a recursive function. Though straightforward, this method may be ineffective if repeated function calls are made. Example: This example shows the recursive approach to find the nth term. JavaScript function fibonacciRecursive(n) { if (n <= 1) return n; return fibonacciRecursive(n - 1) + fibonacciRecursive(n - 2); } const n = 12; console.log(`The ${n}-th Fibonacci number is : ${fibonacciRecursive(n)}`); OutputThe 12-th Fibonacci number is : 144 Iterative Approach We compute the Fibonacci number sequentially using a loop. Due to the elimination of pointless function calls, it is more efficient than the recursive method. Example: This example shows the Iterative approach to finding the nth term. JavaScript function fibonacciIterative(n) { let fib = [0, 1]; for (let i = 2; i <= n; i++) { fib[i] = fib[i - 1] + fib[i - 2]; } return fib[n]; } const n = 12; console.log(`The ${n}-th Fibonacci number is: ${fibonacciIterative(n)}`); OutputThe 12-th Fibonacci number is: 144 Dynamic Programming ApproachWe prevent unnecessary calculations by storing previously computed Fibonacci numbers in an array, which increases algorithmic performance. Example: This example shows the Iterative approach to finding the nth term. JavaScript function fibonacciDynamic(n) { let fib = [0, 1]; for (let i = 2; i <= n; i++) { fib[i] = fib[i - 1] + fib[i - 2]; } return fib[n]; } const n = 2; console.log(`The ${n}-th Fibonacci number is: ${fibonacciDynamic(n)}`); OutputThe 2-th Fibonacci number is: 1 ConclusionWe have discussed three methods that you may use in JavaScript to find the n-th Fibonacci number. Iterative and dynamic programming methodologies are more efficient than the recursive approach, which is simpler but less effective. Comment More infoAdvertise with us Next Article JavaScript Program to Find n-th Fibonacci Number akhilboy Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Program Similar Reads JavaScript Program to Display Fibonacci Sequence Using Recursion In this article, we will explore how to display the Fibonacci sequence using recursion in JavaScript. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. Recursion is a powerful technique in programming that involves a function calling itself. A recu 3 min read JavaScript Program to Print Nth Non Fibonacci Number JavaScript program to print the nth non-Fibonacci number. Non-Fibonacci numbers are integers that are not part of the Fibonacci sequence. Below are the approaches to print the Nth non-Fibonacci number: Table of Content Using a LoopUsing RecursionUsing a LoopWe are using a while loop to find the nth 2 min read JavaScript Program to print Fibonacci Series The Fibonacci sequence is the integer sequence where the first two terms are 0 and 1. After that, the next term is defined as the sum of the previous two terms. The recurrence relation defines the sequence Fn of Fibonacci numbers:Fn = Fn-1 + Fn-2 with seed values F0 = 0 and F1 = 1Examples:Input : 5 4 min read JavaScript Program to Sum of Fibonacci Numbers at Even Indexes up to N Terms Fibonacci numbers are a sequence of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. In this article, we will explore how to calculate the sum of Fibonacci numbers at even indexes up to N terms using JavaScript. Sum of Fibonacci Numbers at Even Indexes up to N T 2 min read PHP Program for Nth Fibonacci Number The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. In this article, we will write a PHP program to find the Nth Fibonacci number. Table of Content Iterative MethodRecursive MethodIterative MethodFirst, we define a func 2 min read How to calculate the Fibonacci series in JavaScript ? Fibonacci series is a number series that contains integers in the following pattern. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ..In terms of mathematics, the general formula for calculating the Fibonacci series is fn = fn-1 + fn-2 , where n ⥠2Here, f0 = 0 and f1 = 1. We need to calculate n Fibonacci num 4 min read How to Check if a Given Number is Fibonacci Number in JavaScript ? The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. Checking for Fibonacci numbers involves verifying whether a given number appears in this sequence. The first few Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, and 4 min read R Program to Print the Fibonacci Sequence The Fibonacci sequence is a series of numbers in which each number (known as a Fibonacci number) is the sum of the two preceding ones. The sequence starts with 0 and 1, and then each subsequent number is the sum of the two previous numbers. The Fibonacci sequence has many applications in various fie 2 min read C Program to Find the Sum of Fibonacci Numbers at Even Indexes up to N Terms Here, we will build a C Program to Find the Sum of Fibonacci numbers at even indexes up to N termsFibonacci Numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, â¦â¦Input: N = 5Output:88 // Sum of the elements at even indexes = 0 + 1 + 3 + 8 + 21 + 55 = 88Approach:This approach includes solving the 2 min read Fibonacci Series Program In Python Using Iterative Method Fibonacci series is a series where each number is the sum of its two previous numbers. In this article, we are going to generate Fibonacci series in Python using Iterative methods. We will be covering both the loops i.e. for loop and while loop. In this article, we will be covering all the concepts 4 min read Like