In programming
A named value that can change while the program runs.
score = 0, then score = score + 10
The name stays the same; the value inside is replaced.
Free Lesson
A variable is a named container that stores a value so a program can use it and change it later, like a labeled box you can open, read and refill. In math and science the word means something close: a quantity that is unknown or that can change.
Make one yourself below: name a box, put a value in it, and watch a tiny program change it one line at a time.
Interactive lab
Name the box, choose what goes in it, then press Next to run a three-line program one line at a time. Try a number, a word, or true. Everything runs in your browser.
Valid name. Stored as a number: 10
Press Next to run line 1.
No boxes yet.
Five quick questions across code, math and science.
Three meanings
A named value that can change while the program runs.
score = 0, then score = score + 10
The name stays the same; the value inside is replaced.
A letter that stands for an unknown or changing number.
2x + 3 = 11, so x = 4
You solve for it, and it does not change partway through the problem.
Any factor in an experiment that can change or be changed.
Independent: water given. Dependent: plant height. Controlled: soil, light.
Change one thing, measure another, keep the rest the same.
Data types
| Type | Also called | Example (Python) | Use it for |
|---|---|---|---|
| Number | integer / float | age = 12, price = 4.99 | Counting, scores, money, measurements |
| Text | string | name = "Ada" | Names, messages, anything in quotes |
| True/false | boolean | is_logged_in = True | Yes/no answers and if checks |
| List | list / array | scores = [90, 72, 85] | Many values under one name |
A variable that should never change is a constant. JavaScript has const TAX_RATE = 0.08;; Python writes the name in capitals by convention.
Naming rules
Names are case-sensitive: Score and score are two different boxes. Type a bad name into the lab above to see the error.
How to
Step 1
Choose a name that says what the value is, like score or user_name. Start with a letter and skip spaces.
Step 2
Decide what goes in the box first: a number like 0, text in quotes like "Ada", or True/False.
Step 3
Write the name, an equals sign, then the value: score = 0 in Python, or let score = 0; in JavaScript.
Step 4
Use the name anywhere you need the value, and assign again to change it: score = score + 1.
Code Card turns your Claude Code, Codex, and OpenClaw sessions into a public developer profile with activity graphs, token breakdowns, badges, and a shareable card. Start with npx code-card.
FAQ
A variable is a named container for a value. In code it is like a labeled box: you put a value in, read it by its name, and swap in a new value whenever you need to.
In programming, a variable is a name that points to a value stored in the computer's memory. The program uses the name to read the value or replace it, so the same code can work with different data.
Independent (the one you change on purpose), dependent (the one you measure) and controlled (the ones you keep the same so the test is fair).
A variable can change while the program runs. A constant is set once and never changes, like const PI = 3.14159 in JavaScript or a name written in CAPITALS by convention in Python.
Start with a letter or underscore, use only letters, digits and underscores, never use spaces, and avoid reserved words like if, for or class. Names are case-sensitive, so Score and score are two different variables.
Because its value can vary. The name stays the same while what it holds changes over time, or, in math, stands for a number you have not worked out yet.