Table of Contents
Back Button
Back to Chapter
Control Statements
No items found.
Function & Events
No items found.
Array and its Types
No items found.
OOP : Object Oriented Programming
No items found.
Javascript Standards
No items found.
No items found.
Javascript : Advanced 1
No items found.
Javascript : Advanced 2
No items found.
Additional JavaScript
No items found.

Recursive Function

The Function which Calles Itself is known as Recursive Function.


If I ask you to print numbers from 1 to 10 without using loop.

Can you do??? No... So, Let me introduce you to the concept of Recursion.


// code recursion(); //code } recursion();


Once you call the Function recursion then the statements inside the function will run. i.e. recusion(); will be called again.


var no=1; function printNo() { console.log(no); no+=1; if(no <= 10) { printNo(no); } } printNo(); // Output // 1 // 2 // 3 // 4 // 5 // 6 // 7 // 8 // 9 // 10


We have declared a Global Scope Variable no

Then Function called printNo();

Let's Understand the Function printNo();

At First, no is printed in Console.

no+=1 i.e. no = no + 1

Then we have used, If Condition

if no is less than 10 then function will be called again.

otherwise, function will be terminated.


You Should be Very Careful while using the Recursive Function. Because Many Beginners When Try to do Looping using Recursive Function, They usually Forget to Put Condition to Stop the Loop, resulting in Infinite Loop and Crashing of the Program.

So, Don't Forget to Put Condition to Stop the Loop, you can use if condition to stop the Iteration of The Loop.

Ask queries
Contact Us on Whatsapp
Hi, How Can We Help You?