Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

recursion javascript

function countDown(fromNumber) {
    console.log(fromNumber);

    let nextNumber = fromNumber - 1;

    if (nextNumber > 0) {
        countDown(nextNumber);
    }
}
countDown(3);
Code language: JavaScript (javascript)
Comment

recursive function javascript

/*
Recursion is when a function calls itself until someone stops it. 
If no one stops it then it'll recurse (call itself) forever.
*/

// program to count down numbers to 1
function countDown(number) {
    // display the number
    console.log(number);
    // decrease the number value
    const newNumber = number - 1;
    // base case
    if (newNumber > 0) {
        countDown(newNumber);
    }
}

countDown(4);
// Out put: 
4
3
2
1
Comment

Recursion In DOM

function walkTree(node) {
  if (node == null) //
    return;
  // do something with node
  for (var i = 0; i < node.childNodes.length; i++) {
    walkTree(node.childNodes[i]);
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: angular submit with required 
Javascript :: javascript get phone number from string 
Javascript :: how to change the first Letter to uppercase js 
Javascript :: if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1. 
Javascript :: submit form using jquery 
Javascript :: react footer 
Javascript :: chartjs begin at 0 
Javascript :: insertadjacenthtml javascript 
Javascript :: how to delete node_modules 
Javascript :: how to get checked value of checkbox in jquery 
Javascript :: upload files to api using axios 
Javascript :: add numbers in array 
Javascript :: regex for valid phone number 
Javascript :: javascript write to text file 
Javascript :: how to find hcf of 2 numbers in javascript 
Javascript :: close div when click outside angular 7 
Javascript :: javascript set variable if not defined 
Javascript :: node javascript foreach limit 
Javascript :: javascript if string empty 
Javascript :: javascript max array 
Javascript :: get first 10 characters of string javascript 
Javascript :: loop through json array and get key name 
Javascript :: Execute JavaScript using Selenium WebDriver in C# 
Javascript :: javascript if value is a string function 
Javascript :: using .env in cra 
Javascript :: componentwillunmount 
Javascript :: object values 
Javascript :: async import javascript 
Javascript :: create csv file nodejs 
Javascript :: js array includes 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =