Skip to main content

Online JavaScript compiler

Visualize

See your code run, step by step

The fastest way to understand loops, recursion, lists and objects, and to find bugs.

  • The line that just ran and the line that runs next, highlighted in your code.
  • A plain-English note on every step: which variable changed, which function was called, what it returned.
  • The call stack as cards, so recursion is easy to follow: every call is numbered and shows its own variables.
  • Arrays as indexed boxes, objects, Maps and Sets as tables, with arrows from each variable to what it points to.
  • When the code fails, the error explained in simple words, with a button to jump to the step where it happened.
  • Play, pause, go back and forward, or drag the slider. Works on phones too.
Open the JavaScript code visualizer

What it supports

JavaScript ES2024, run in your browser

  • Modern JavaScript: let and const, arrow functions, classes, arrays, objects, Map and Set.
  • console.log prints numbers, text, arrays and objects clearly.
  • Type what prompt() reads in Input, one value per line.
  • Runs stop after 5 seconds, so a loop that never ends cannot freeze anything.
  • It runs entirely in your browser: nothing is sent anywhere.

Input

How to read input in JavaScript

Programs that read from the keyboard get their input from the Input box. Type one value per line, then press Run. The program reads the lines in order, just as it would from a keyboard.

const n = Number(prompt());           // first line
const [a, b] = readline().split(" ").map(Number); // two numbers on one line
const rest = require("fs").readFileSync(0, "utf8"); // everything

Questions

Frequently asked questions

Where does my JavaScript run?
In your own browser, inside a locked sandbox: nothing is sent to a server, so it runs instantly and works on a phone too. The sandbox has no access to this page, your cookies, your storage or the internet.
How do I read input in JavaScript here?
Type the input in the Input box, one value per line. prompt(), readline() and input() each read the next line (and give null when there are no more). To read everything at once, use require("fs").readFileSync(0, "utf8"). The readline module and process.stdin work too, like in Node.js.
Can I use document, window or npm packages?
No. Programs run like Node.js scripts without a web page, so there is no document or window: print with console.log. require() only has fs (to read the Input box), readline and util. Each run stops after 5 seconds or 64 KB of output.

Learn

Learn JavaScript step by step

Press Visualize on any program to watch it run line by line: the fastest way to understand loops, functions and objects.