Recursion
Recursion is the technique of making a function call itself.
This technique provides a way to break complicated problems down into simple problems which are easier to solve.
It is a feature used in creating a function that keeps calling itself but with a smaller input every consecutive time until the code's desired result from the start is achieved.
Adding two numbers together is easy to do,
but adding a range of numbers is more complicated.
In the following example, recursion is used to add a range of numbers together by breaking it down into the simple task of adding two numbers:
let count = 1;
function m1(number){
if(count > number){
return;
}
console.log("Hello World :- "+count);
count++;
m1(number);
}
m1(10);
Top comments (0)