Recursion & Fibonacci Sequence – JavaScript Tutorial for Beginners




What is recursion? In JavaScript, recursion is a way to solve a problem by calling a function from within that same function. While this may be considered one of the most complicated ideas in software development, the concept is really quite simple. As an example to illustrate this tutorial, we’ll write some JavaScript code implementing a function that calculates the Nth number of the Fibonacci sequence.

Three things to remember about recursion:

1. Always make progress towards a solution every time you recurse.
2. Always have a break point where the function stops calling itself.
3. If you don’t design your recursive function right, or if you overuse the method, you can exhaust your stack, and the program will run out of memory.

Copyright (c) 2013 Rodrigo Silveira http://www.easylearntutorial.com

Original source


6 responses to “Recursion & Fibonacci Sequence – JavaScript Tutorial for Beginners”

Leave a Reply