JOVANA
Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

Variables & Types: Boxes for Your Data

A variable is a named box that holds a value, and the value's type quietly decides what you're allowed to do with it.

The idea: a named box

Imagine you're cooking and you scoop some sugar into a small jar, then slap a label on it that says "sugar." From now on you don't think about that exact pile of crystals — you just say "sugar" and grab the jar. A variable is exactly that jar: a named box where you store a value so you can reach for it later by name instead of remembering the value itself.

Why bother? Because programs juggle lots of values — a player's score, someone's name, the price of a coffee — and these values change as the program runs. A variable gives each value a handle you can hold onto. Write the name once, and the program quietly fetches whatever is currently inside the box.

Naming the box and putting something in

Making a variable takes two moves: pick a name, and put a value in. In most languages the equals sign = does the "put in" part. Read it not as "is equal to" but as an arrow: "take this value and store it in this box." The name goes on the left, the value goes on the right.

score = 0
name = "Mira"

score = score + 10   # the box now holds 10
Two boxes get filled, then score is changed: read its current value (0), add 10, store 10 back.

That last line surprises beginners, so look closely. The right side runs first: score is currently 0, plus 10 makes 10. Then that 10 is stored back into the score box, replacing the old value. The box didn't multiply — it just got a new content.

Types: what kind of thing is in the box

Every value you store has a type — its "kind." The four you'll meet first are: text (a string of characters, like a name), number (for counting and math), true/false (a yes-or-no answer, called a boolean), and a list (several values lined up in order). The type isn't just a label; it decides what you're allowed to do with the value.

title = "Hello"      # text
price = 4.5          # number
inStock = true       # true/false
colors = ["red", "blue"]   # a list
Four common types. Notice text wears quotes, numbers don't, and a list sits inside square brackets.

Here's why the type matters. You can multiply two numbers (price times quantity) but multiplying two names is nonsense. You can ask a list "how many items do you hold?" but that question means nothing to a single number. The type quietly defines the menu of sensible actions for each value.

The trap: "2" is not 2

Now the classic stumble that catches almost every beginner. Look at 2 and "2". To your eye they're the same. To the computer they are different types: 2 is a number, and "2" — wearing quotes — is text that just happens to look like a number. And the plus sign + does different jobs depending on the type.

2 + 2       // number + number  -> 4
"2" + "2"   // text + text      -> "22"
Same symbol, two meanings: with numbers + adds; with text + glues them end to end.

With numbers, + adds: 2 + 2 is 4, as you'd hope. With text, + glues strings together end to end, so "2" + "2" becomes "22" — the two characters stuck side by side. Nothing is broken; the computer did exactly what + means for each type. The surprise comes only because the quotes are easy to miss.

This bites hardest when a value sneaks in as text without you noticing — numbers typed into a web form, for instance, usually arrive as text. So if your math ever produces "510" where you expected 15, don't panic: check the type first. A number wearing quotes is the usual culprit, and converting it back to a real number fixes it.

Recap

A variable is a named box for a value. You fill it with = ("store this on the right into the box on the left"), read it by its name, and overwrite it whenever you like. That one idea is the backbone of almost every program you'll ever write.

Each value also has a type — text, number, true/false, or a list — and the type decides what's sensible to do with it. The one trap to remember: "2" (text) and 2 (number) look alike but behave differently, so when arithmetic surprises you, check the types before anything else. Master these two ideas and the rest of programming has somewhere solid to stand.