Variables
Names for things — boxes the computer can put a value in and find again.
Story — the locker room
Imagine a small row of lockers along a gym wall. Each locker has a label on the door — score, name, wins — and a single thing tucked inside.
That is what a variable is. The label is the name you use in your code; the thing inside is the value. You can swap what is inside without changing the label, and you can read the contents by name without rummaging through every other locker.
Locker Attendant says
See it — fill the lockers
Press Step to advance one tick. Watch the highlighted locker — the label never moves; only the contents change.
Text-only trace
- Three lockers exist with labels: score, name, wins.
Try it — order the program
The four lines below build a small program. Put them in an order that would actually run.
Drag the pieces — or tab to one and use the ↑/↓ buttons — to put the program in order.
print(name, score)name = "Asha"score = 0score = score + 10
Code it — five languages, one idea
The same little program in five popular languages. Notice what is shared (a name, a value, an assignment) and what is just punctuation or a type label.
score = 0
score = score + 10
name = "Asha"
print(name, score) # Asha 10Walk through it line by line
Each click of Next executes one line. Watch the variable panel on the right.
1score = 02score = score + 103name = "Asha"4print(name, score)
Quiz it — make it stick
No Dumb Questions
Real questions other learners asked on this page.
Why are some variables typed (Java, C++) and others are not (Python, JavaScript)?
Statically typed languages want to know what fits in the locker before the program runs, which catches mistakes early and lets the computer pack values more efficiently. Dynamically typed languages are happy to let the locker hold anything and check at run time. Both work — they just trade flexibility for safety.What is the difference between `=` and `==`?
`=` is assignment — put a value into a locker. `==` is a question — does the value in this locker equal that other value? They look similar but do completely different jobs. Mixing them up is one of the most common beginner bugs.Can I change a variable as many times as I want?
In most languages, yes — that is what `let` (JS) or a plain Python name allows. Some languages have a special "constant" form (`const`, `final`) that locks the value after the first assignment. That is useful when you want the reader to know "this never changes after this point."