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 :: javascript link detector 
Javascript :: get vue-emoji-picker 
Javascript :: crud in node 
Javascript :: nesting arrays javascript 
Javascript :: How to add js file to a site through url 
Javascript :: cypress check if an element is visible 
Javascript :: string to array in js 
Javascript :: js electron setup 
Javascript :: scroll to div bottom 
Javascript :: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 
Javascript :: check if javascript function is true 
Javascript :: onkeypress 
Javascript :: tinymce react 
Javascript :: concatenate arrays javascript 
Javascript :: java script alerts 
Javascript :: notify.js 
Javascript :: html to pdf javascript libraries 
Javascript :: firebase integration in react 
Javascript :: mongoose save return id 
Javascript :: javascript var in quotes 
Javascript :: call function 
Javascript :: dom methods 
Javascript :: js object delete value by key 
Javascript :: setup error handler in express framework 
Javascript :: javascript pass this to callback 
Javascript :: node.js Readable Streams 
Javascript :: how to make pdf of web page 
Javascript :: destructuring an array 
Javascript :: javascript get the last array element 
Javascript :: how to take last element of array javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =