Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Recursion Not Clicking? Try Rewriting Each Call as an Expression

JSVisualizer is a free browser-based tool that runs JavaScript step by step and shows you what's happening in 12 different views. There's nothing to install. This is part of a series that uses it to understand classic algorithms by watching them run, but this post stands on its own. For an overview of the tool, see the first post in the series . This time the topic is recursion , and the star of…

JSVisualizer is a free online tool that lets you run JavaScript code step by step and view it in 12 different ways. This article uses the tool to explain the concept of recursion, using the example of a function that calculates x raised to the power of n.

One common source of confusion for beginners is how a function can call itself before it's even finished being defined. However, defining the function does not run its code, so when the function is called, it already exists and can be used. The key is that the function must have a stopping condition, where it returns a known answer and stops calling itself. In this example, the base case is when n equals 0, where the function returns 1.

When looking at the code in the Subst view, each function call is replaced with the expression that the function returns. This shows the recursion as a series of smaller problems being solved, with each call using the same rule to replace itself with a slightly smaller version of the same problem. In this case, the argument n is reduced by 1 each time, until it reaches the base case.

During this rewriting process, all the multiplication operations are waiting to happen, as they can't be performed until the innermost call returns an answer. Only when the base case is reached and returns 1 can the multiplication begin, starting from the innermost call and working its way outward. This can make the process seem confusing, but in reality, each call creates a new frame for the computation.

In summary, recursion involves defining a function that calls itself, with a base case to stop the recursion and ensure the function eventually returns an answer. By looking at the code in the Subst view, it's possible to see how the problem is broken down into smaller versions of itself, with each call waiting for the results of the next smaller call before performing its own multiplication.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

More from Dev.to on urgent.news

Get the news by email. Yesterday's most-covered stories, every morning.

See today's edition · More options

More in Tech

The best gamified health and fitness apps (2026): an honest comparison

Disclosure: we make New Game Plus, one of the apps on this list. We've tried to describe every app fairly, including where ours isn't the right pick.

  • Habitica is an RPG app for habit tracking with optional cosmetic upgrades
  • Zombies, Run! is a running app with audio adventure game mechanics
  • New Game Plus tracks various health metrics with a pixel-art hero

Windows certificate inventory with PowerShell: RSA and ECC

Start with one service. Its Windows certificate store can contain an expired certificate, the replacement waiting for a maintenance window, and a certificate issued for an entirely different…

  • PowerShell can inventory Windows certificates in personal store
  • Certificates have RSA or ECC public key algorithms
  • Verify TLS termination point and fingerprint comparison for secure connections

Your Agent Isn't Bad at Tools. Your Tool Descriptions Are.

Your Agent Isn't Bad at Tools. Your Tool Descriptions Are. Every vendor demo shows an agent gliding through tool calls like it was born to it.

  • Agent's performance depends on tool descriptions, not model intelligence
  • Detailed descriptions critical for tool selection accuracy
  • Validation gate essential between model output and system systems

More from Saturday, 5 December 2026 →