Here is an example of a program that generates the Fibonacci series in JavaScript:

function fibonacci(n) {
  let a = 0, b = 1, c, i;
  
  if (n == 0) return a;
  if (n == 1) return b;
  for (i = 2; i <= n; i++) {
    c = a + b;
    a = b;
    b = c;
  }
  return b;
}
console.log(fibonacci(10));

This program defines a function called ‘fibonacci()’ that takes in a number ‘n’ as a parameter. The function uses a loop to generate the Fibonacci series, starting with the first two numbers, 0 and 1. On each iteration of the loop, the next number in the series is calculated by adding the previous two numbers together. The function returns the ‘n’th number in the series.

You can test the function by calling ‘console.log(fibonacci(10))’ which will print the 10th number of the fibonacci series.

Also Read:

Categorized in: