JavaScript Recursive function

Last Updated Jul 29, 2015, 07:00:14 PM





JavaScript Recursive function

JavaScript recursive function is a function that calls itself.

Recursion is one of the most simple programming concepts. It sounds straightforward, but once you start working with it and try to really understand how it works, you may find yourself dizzy and confused.

Recursion is used to solve problems that contain smaller sub-problems. A recursive function can receive two inputs: a base case (ends recursion) or a recursive case (continues recursion).

Example

Try It Now

Why is Recursion Good For?

Recursion is a technique for iterating over an operation by having a function call itself repeatedly until it arrives at a result. Most loops can be rewritten in a recursive style, and in some functional languages this approach to looping is the default.


Other JavaScript functions you might want to learn

JavaScript Anonymous functions

JavaScript named functions

JavaScript Inner functions

JavaScript function with parameters

Sources and Credits

The source of the content has been referred and updated with Mozilla Developer Network and W3C Organization

Last Updated Jul 29, 2015, 07:00:14 PM



Browser compatibility

Feature
Basic support Yes Yes Yes Yes Yes Yes Yes