DEV Community

Tetsuo TANAKA
Tetsuo TANAKA

Posted on Edited on

See Your JavaScript Run 12 Different Ways: Meet JSVisualizer (and How It Differs from Python Tutor)

Why "seeing" code matters

If you've ever learned to program — or taught someone who is — some of these will sound familiar:

  • You copy an example, run it, and get the right answer. But you couldn't explain why it's the right answer.
  • Recursion makes perfect sense during the lecture. Then you sit down to write a recursive function and your mind goes blank.
  • You sprinkle console.log everywhere to chase a value, and halfway through you forget what you were looking for.

The root problem is that a program's behavior is invisible. Source code is static text, but when it runs it produces state that changes over time. One reason people struggle with programming is how hard it is to picture that hidden motion accurately.

This series introduces JSVisualizer, a web app that runs JavaScript one step at a time and shows you what's going on through 12 different views.

https://tntetsu.github.io/JSVisualizer/

It runs entirely in your browser. Nothing to install, no account needed.

The interface follows your browser's language (English, or Japanese if your browser prefers Japanese). You can switch at any time with the EN / 日 button in the top-right corner.

In this first post, I'll give you a quick tour and compare JSVisualizer with the well-known Python Tutor. From the next post on, each article takes one concrete topic, from programming basics to algorithms and data structures, and pairs it with the view that explains it best.

The screen at a glance

JSVisualizer: source code on the left, the Call Stack view on the right

The screen has two halves:

  • Left: your code. Paste in any JavaScript and run it. The line being executed is highlighted in blue, and the expression being evaluated right now is highlighted in orange. When execution is inside a function, the expression that called it (here, fact(n - 1)) gets a dashed purple underline.
  • Right: the views. Each tab shows the same moment of the same run from a different angle. Above is the Call Stack view, showing calls piling up: fact(4) → fact(3) → fact(2).

To use it, write some code, press ▶ Run, and use the buttons along the top to step forward (or backward). You can also drag the slider to jump to any point in the run.

The user manual explains every button and view in detail. You can also open it with the ? button in the top-right corner.

If you'd like to try it right away, open the link below. It loads the factorial example used in this post, so there's nothing to type. Press ▶ Run, step with ▷ Human, and switch tabs on the right to see the same program from different angles.

▶ Open in JSVisualizer (factorial, Subst view)

Feature 1: Step at four levels of detail

You choose how big a "step" is. Each level has its own forward and back buttons:

Buttons Unit Use it when you want to…
◀ Expr / ▶ Expr Expression (finest) see the order in which something like a + b * c is evaluated
◀◀ Stmt / ▶▶ Stmt Statement follow the flow statement by statement
◁ Human / ▷ Human "Human-friendly" step stop only at meaningful changes: assignments, condition checks, loop updates (the best place for beginners to start)
⏪ Func / ⏩ Func Function call focus on where functions are entered and where they return

A typical workflow: use Human steps to get the big picture, then switch to Expr steps when something puzzling happens. Every level can step backward, so when you think "wait, what just happened?", you can rewind instantly.

Feature 2: Twelve views

The views fall into three groups, depending on what they help you understand (some views fit more than one group):

Group What it shows Views
State and how it changes Variable values, stored data, and how they change Variable, Exec Trace, Memory
Computation and flow How expressions are computed, the order and count of what runs, and function calls Expr, Subst, Control Flow, Heatmap, Call Stack, Call Tree, Lifetime
Data structures How data is laid out and linked Arrays, Objects

Views also differ in how they handle time. Some update what they show every time you step (e.g. Variable, Call Stack). Others lay out the whole run and mark where you are in it (e.g. Exec Trace, Subst, Heatmap). The first kind is good for following changes as they happen; the second for seeing the run as a whole.

For example, here is the Subst view (short for substitution). It rewrites the recursive call fact(4) the way you'd expand it by hand — 4 * fact(3), then 4 * 3 * fact(2), and so on — leaving the whole expansion on screen at once.

Subst view: fact(4) expands to 4 * 3 * 2 * 1 and evaluates to 24

Same program, same moment: the Call Stack view shows calls stacking up, while the Subst view shows an expression being rewritten. If one picture doesn't click, another one might. That's the whole reason for having twelve.

How is this different from Python Tutor?

Python Tutor is the best-known program visualizer out there and is used by learners all over the world. Despite the name, it also supports Java, C, C++, and JavaScript. So the first question people ask about JSVisualizer is usually, "How is this different from Python Tutor?"

JSVisualizer Python Tutor
Languages JavaScript only Python, Java, C, C++, JavaScript
Step size 4 levels (expression, statement, human-friendly, function), forward and back Mainly by line, forward and back
Visualizations 12 purpose-built views, switchable via tabs Centered on a frames-and-objects diagram
Which expression is running Highlights the exact expression An arrow points to the line
The big picture of recursion (call tree, expansion by substitution) Call Tree and Subst views In JavaScript mode, frames disappear once a call returns
Sharing Links that open specific code (via ?code=, see below) Shareable links and embed codes for a specific run

(The Python Tutor details were checked in the JavaScript mode of pythontutor.com on October 30, 2026.)

Python Tutor's diagram — frames on the left, objects on the right, arrows for references — is an excellent way to understand how variables relate to memory. JSVisualizer has a view of the same kind, called Memory.

Where JSVisualizer differs is that you're not limited to that one diagram. You pick the view that fits the question you're asking:

  • How does a variable change as a loop runs? → Variable, Exec Trace
  • How does a complicated condition turn into true or false? → Expr (stepping one expression at a time)
  • Which branch of an if did the program take? → Control Flow
  • Is my recursive function computing the same thing over and over? → Call Tree

So which one should you use?

It's less about which is better and more that they suit different learning goals.

Reach for Python Tutor when you…

  • are learning Python, C, or another language besides JavaScript
  • want to really understand variables, references, and memory ("boxes and arrows")
  • want to hand students a single link that replays one specific run

Reach for JSVisualizer when you…

  • are learning or teaching JavaScript
  • want to see things a memory diagram can't easily show: evaluation order, which lines ran and how often, how recursion branches out
  • want to look at the same program from several angles

What code you can run

JSVisualizer runs code that uses the main ES2015+ syntax (let, const, arrow functions, classes, and so on) and checks results with console.log(). Browser features like changing the page (the DOM) or making network requests aren't available, and asynchronous code (setTimeout, async/await) isn't reproduced faithfully. A run also stops once it passes 50,000 steps, in case a loop never ends. All code runs inside your browser and is never sent to a server. See "Writing your own code" in the manual for details.

For instructors: links that open specific code

You can add parameters to the URL so that JSVisualizer opens with a specific piece of code already loaded:

https://tntetsu.github.io/JSVisualizer/?code=<URL of a code JSON>&view=<view to show first>
Enter fullscreen mode Exit fullscreen mode
  • code: the URL of a JSON file shaped like { "title": "...", "code": "..." }
  • view: the view that opens the first time the reader presses ▶ Run (trace, subst, controlflow, …)

Encode the code URL with encodeURIComponent() before adding it. Also, if the server hosting the JSON doesn't allow other sites to load it (its CORS settings), JSVisualizer may not be able to read it.

Put a link like this in your slides or assignments — "open this, press Run, and step through it" — and every student starts from the same screen without retyping any code. Every post in this series ends with a link in this format.

In class, you can go beyond just showing a run: have students predict what the program will do before running it, check their predictions by stepping through, explain why it behaved that way, and then change the code and try again. Every post in this series is built around that way of learning.

Try it yourself

This link opens the factorial example from this post. Press ▶ Run and the Subst view opens. Use ▷ Human to step forward, and try switching between tabs as you go.

▶ Open in JSVisualizer (factorial, Subst view)

function fact(n) {
  if (n <= 1) {
    return 1;
  }
  return n * fact(n - 1);
}
console.log(fact(4));
Enter fullscreen mode Exit fullscreen mode

Of course, you can also open the home page and paste in your own code.

Wrapping up

  • JSVisualizer is a web app that steps through JavaScript and lets you watch it run through 12 different views. Nothing to install, no account needed.
  • You can step at four levels of detail, and step backward at every level.
  • Beyond the memory diagram that Python Tutor does so well, you can pick a view that matches what you want to know: evaluation order, branching, execution counts, or how recursion unfolds.
  • Looking at the same program a different way can make it click. Predict what it will do, check by stepping through, then change the code and try again.

Next up: the first big hurdle in programming — the for loop. We'll take the classic "add up 1 through 5" program and use the Variable view to follow sum and i one step at a time.

Top comments (0)