{
  "id": 23707976,
  "title": "Recursion Not Clicking? Try Rewriting Each Call as an Expression",
  "url": "https://urgent.news/2026/12/05/recursion-not-clicking-try-rewriting-each-call-as-an-expression",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-05T22:00:00.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/tntetsu/recursion-not-clicking-try-rewriting-each-call-as-an-expression-158g"
  },
  "original_language": null,
  "account": "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.\n\nOne 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.\n\nWhen 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.\n\nDuring 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.\n\nIn 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.",
  "summary": "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…",
  "summary_source": "publisher",
  "key_points": [
    "Recursion allows a function to call itself before being fully defined",
    "Base case stops recursion by returning a known answer",
    "Each call is replaced with expression in Subst view, breaking problem into smaller versions"
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "outlets_capped": false,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}