Cache the length of the array so you would have the following:

function recurse(node) {
    for(var i = 0, count = node.children.length; i < count; i++) {
        recurse(node.children[i]);
    }
} 

You should always cache especially when you're dealing with HTMLCollections.

Answer from MackPro on Stack Overflow
🌐
freeCodeCamp
freecodecamp.org › news › recursion-in-javascript-simplified
How Does Recursion Work? Simplified in JavaScript with Examples
October 7, 2022 - By Dillion Megida Recursion works similarly to how loops do in JavaScript. Loops allow you to execute a set of code multiple times as long as a condition is true. In this article, I will explain what Recursion is and how it works in JavaScript.
🌐
DEV Community
dev.to › thawkin3 › recursion-vs-loops-in-javascript-14em
Recursion vs. Loops in JavaScript - DEV Community
August 26, 2022 - If we just called our function recursively, we’d end up in an infinite loop, so we need some way to break out. That’s why we have the condition that handles when x <= 1. When we reach that point, we stop recursively calling our factorial function. This is the base case. ... Let’s try a similar example. This time let’s implement the power function, which calculates the result of a base number raised to an exponent. So for example, 2^3 is two raised to the power of three, or 2 * 2 * 2, which is 8. In JavaScript, there are a couple of ways to do power functions natively, like by calling Math.pow(2, 3) or using the exponentiation syntax like 2 ** 3.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › advanced working with functions
Recursion and stack
We can easily see the principle: for an object {...} subcalls are made, while arrays [...] are the “leaves” of the recursion tree, they give immediate result. Note that the code uses smart features that we’ve covered before: Method arr.reduce explained in the chapter Array methods to get the sum of the array. Loop for(val of Object.values(obj)) to iterate over object values: Object.values returns an array of them.
🌐
freeCodeCamp
freecodecamp.org › news › quick-intro-to-recursion
A Quick Intro to Recursion in Javascript
September 3, 2019 - Recursive does not, it simply passes updated parameters between each call. ... In your travels, you may have been warned about the dreaded infinite loop.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript recursive function
JavaScript Recursive Function
November 15, 2024 - This tutorial shows you how to use the recursion technique to develop a JavaScript recursive function, which is a function that calls itself.
🌐
Programiz
programiz.com › javascript › recursion
JavaScript Recursion (with Examples)
Here, we have a recursive function greet() without a base case. As you can see, greet() keeps calling itself until the program runs into an error (RangeError). ... Before we wrap up, let’s put your knowledge of JavaScript Recursion to the test!
🌐
Medium
medium.com › weekly-webtips › simplifying-functional-programming-with-recursion-javascript-aa7007f4b159
Simplifying Functional Programming with Recursion (Javascript) | by Meghan Hein | Webtips | Medium
August 25, 2020 - So, a recursive function executes some code then runs the function again unless an exit condition is met (which stops the circuit of calling itself)… Does this flow sound familiar??
Find elsewhere
🌐
SitePoint
sitepoint.com › blog › javascript › recursion in functional javascript
Recursion in Functional JavaScript — SitePoint
November 11, 2024 - Recursion is best applied when you need to call the same function repeatedly with different parameters from within a loop. While it can be used in many situations, it is most effective for solving problems involving iterative branching, such as fractal math, sorting, or traversing the nodes ...
🌐
Appsmith
community.appsmith.com › content › blog › recursion-vs-loops-simple-introduction-elegant-javascript
Recursion Vs. Loops: A Simple Introduction to Elegant Javascript | Appsmith Community Portal
July 12, 2023 - Copy Or Reference? Understanding Javascript Object Assignments ... One of the key features of functional programming is recursion. A recursive function is one that calls itself. Wait - what? Yes - a function that loops over itself to do its thing. Why? Because we're adventurous like that!
🌐
DEV Community
dev.to › kriegercisneros › recursion-in-js-for-beginners-avoiding-and-infinite-loop-17bh
Recursion in JS for Beginners, avoiding an infinite loop - DEV Community
February 20, 2023 - JavaScript is throwing us this error because we are recursively calling recursionFunction outside of our base case declaration (the "if" statement right at the beginning). Think about it like this: we are calling a function from the body of itself. Which means we are inherently setting up the stage for an infinite loop...
🌐
HowDev
how.dev › answers › introduction-to-recursion-in-javascript
Introduction to recursion in JavaScript
October 7, 2020 - In terms of computer programming, a recursive function is a function that calls itself until it satisfies some exit condition. Otherwise, we’ll be stuck into an infinite loop or, in case of JavaScript, the call stack will overflow.
🌐
Medium
medium.com › @zfrisch › understanding-recursion-in-javascript-992e96449e03
Understanding Recursion in JavaScript | by Zak Frisch | Medium
November 28, 2016 - Understanding Recursion in JavaScript One of the many things that JavaScript has going for it is the ability to recursively call functions. This feature is used to provide important functionality …
🌐
Medium
medium.com › sessionstack-blog › how-javascript-works-recursion-in-javascript-what-it-is-and-how-it-is-used-eef3d734f20d
How JavaScript works: Recursion in JavaScript, What It Is, and How it is used. | by Ukpai Ugochi | SessionStack Blog | Medium
April 11, 2023 - This is because the stack is used to store variables in recursions and not in loops. Recursion in Javascript works exactly as it does in other languages. To have a great understanding of how recursion works, let’s take a look at the makeup of the syntax of the recursive function above.
🌐
DEV Community
dev.to › justin_m_morgan › loops-array-methods-and-recursion-45ng
Loops, Array Methods, and Recursion - DEV Community
November 19, 2021 - Similarly, recursion can tackle the same category of problems as loops and array-functions but (at least in Javascript) suffer from memory-limitations that can crash your program and still require implementing logic manually (unlike using a utility library, such as Lodash or Ramda).
🌐
YouTube
youtube.com › watch
Recursion in JavaScript: Loop Like a Pro! - YouTube
🔥 I taught myself recursion (the hard way) by learning Scheme. In this video I’ll talk about what actually matters, so you can learn Recursion in JavaScript...
Published   September 22, 2022
🌐
Medium
medium.com › @kenny.hom27 › so-you-want-to-build-a-recursive-recursive-recursive-function-in-javascript-ceb508fb1a63
So you want to build a recursive(recursive(recursive…)) function in Javascript | by Kenny Hom | Medium
May 2, 2018 - With a recursive approach, the function uses a branching structure by calling itself until a base condition is satisfied. With an iterative approach, a looping statement such as a for loop is used until a condition fails.
🌐
Medium
medium.com › better-programming › javascript-iteration-v-s-recursion-and-behind-the-scene-e12fe1756343
Iteration versus Recursion in JavaScript | by JeffreyxCodes | Better Programming
May 22, 2019 - In these iterative statements, “label statement”, “continue statement”, and “break statement” can be used in conjunction to give further control of the loop behavior. ... What separates these from the previously mentioned, is that these iterative array methods require a callback function. This is the fundamental difference in how these iterative array methods operate as compared to the traditional iterative statements above as we will see when we take a look behind the scenes. Now that we’ve learned what an iteration is, let’s take a look at recursions and how they differ.
🌐
Better Programming
betterprogramming.pub › recursion-vs-loops-in-javascript-d588c5b0df31
Recursion vs. Loops in JavaScript | by Tyler Hawkins | Better Programming
August 26, 2022 - If you can master those two concepts, recursion isn’t as scary or complex as you think. Recursive code is often shorter to write and (in some cases) easier to read. Let’s walk through five code examples together. We’ll solve each problem first by using a loop, then we’ll solve it using recursion.