Skip to content
Akin C edited this page Apr 15, 2018 · 10 revisions

Welcome to the Javascript-recursive-function- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


Like many other programming languages, Javascript allows to code recursive functions.

A recursive function calls/iterates itself until it reaches a result.

A recursion should be used carefully, because it could exhaust system resources.

One of its use is for traversing the nodes of complex or non-linear data structures.

A code structure for a recursive function in Javascript could look like as follows:

function recursiveFunction(anyNumber)
{
    if(anyNumber === 0)
    {
		
        console.log(anyNumber);
    }
    else
    { 
	console.log(anyNumber);
        recursiveFunction(--anyNumber);
    }
}

recursiveFunction(5);

The code above is decrementing a given number until it reaches 0.

It is important to note that the following call of a function in Javascript should not work:

var f = function Any()
{
    alert("Hello");
}

//Shouldn´t work! - Uncaught ReferenceError
Any();

The code should look like as follows, if a call by name is wanted

function Any()
{
    alert("Hello");
}

//Should work!
Any();

Content

The user interaction part should look like the content as seen below by starting "index.html" in a web browser.

ERROR: No image found!

The binary tree will be traversed with the help of a recursive function. The User decides which knot should be searched for. There is also a broken version of the searching which visualizes an Uncaught ReferenceError.

Note that all files should be placed in the same folder so that the functionality of the code is guaranteed.

Clone this wiki locally