Lesson 4 of 6 · 8 min · 2 hands-on steps

How Code Runs, Step by Step

Watch a program run in slow motion, one line at a time, and see memory change.

The computer reads like you do: top to bottom

A program runs one line at a time, from top to bottom. Each line can change what's stored in memory. A variable is a named box in memory that holds a value.

Use the buttons below to step through this tiny program. Watch the Variables box change after each line.

Two big ideas from that replay:

  1. Order matters. Line 3 can only use coffee and price because they were created on lines 1 and 2.
  2. Variables hold values, not formulas. When coffee changed on line 4, total stayed 6.

Run it yourself

Every code example in this program has a Run button. Try this one, then change the numbers and run it again. Experimenting is how you learn.

JavaScript · try it
Loading…

The #1 habit of good programmers: before you run code, predict what it will do. Then run it. When you're wrong, you just learned something.

🧪 Practice: 2 steps

0 / 2 done

Step 1 of 2 · Predict, then run

Read this code before you run it. What will it print? Say it out loud, then press Run tests ▶.

Then change only the second line so the program prints 15.

JavaScript
Loading editor…

Output appears here. Press Run or Ctrl/⌘ + Enter.

✅ Check your understanding

  1. In what order does a computer run your code?

  2. After `let x = 2;` then `x = x * 3;`, what is x?

Create a free account to track your progress.