I'm new to Javascript and was reading up on it, when I came to a chapter that described function recursion. It used an example function to find the nth number of the Fibonacci sequence. The code is as follows:
function fibonacci(n) {
if (n < 2){
return 1;
} else {
return fibonacci(n-2) + fibonacci(n-1);
}
}
console.log(fibonacci(7)); //Returns 21
I'm having trouble grasping exactly what this function is doing. Can someone explain what's going on here? I'm getting stuck on the 5th line, where the function calls itself. What's happening here?