Data Types
Prerequisites: Variables
A data type describes what kind of value something is, and what you can do with it. The handful of types below cover almost everything you store early on:
- Number —
25,3.14— used for counting and math. - String —
"hello"— text, always inside quotes. - Boolean —
true/false— a yes/no value, used for decisions.
Real-world analogy: the type is like the kind of box you have — a
box built for liquid works differently than one built for books, even
though both are "boxes." Adding two numbers (2 + 3 = 5) is different
from adding two strings ("2" + "3" = "23", joining the text) — same
operator, different behavior, because the type is different.
Common mistakes
- Mixing up a number and a string that looks like a number
(
"25"is text,25is a number — they don't automatically behave the same way).