You can call the same function again and again with some base condition called recursion. Following is the code −
Example
function recursiveFunction(num) {
console.log(num);
if (num > 0) {
recursiveFunction(num - 1);
}
}
recursiveFunction(5);To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo304.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo304.js 5 4 3 2 1 0