Data types: different kinds of information — Computing, 11–13 years
Computers need to know whether something is a number, a piece of text, or a yes-or-no value. Data types help a program handle each kind safely.
Information comes in kinds
A number, a word and a yes-or-no answer may all be stored by a computer, but they are not the same sort of thing. A data type tells the program what kind of information it has, so it knows which actions make sense.
Why bother naming the kind?
Without types, a program might try to add a street name to a score, or treat the number 12 as the text “12”. Computers need this distinction to reject nonsense and choose the right operation instead of guessing silently.
A number or text?
Suppose a game stores a player’s score as the number 12. Step 1: adding 5 gives 17. Step 2: if the score were the text “12”, joining “5” would give “125”, not 17. The type changes what the instruction means.
“It looks like a number”
A common mistake is thinking that anything made of digits is automatically a number. That is reasonable because 12 and “12” look identical on screen. The difference appears only when the program calculates with one or joins text with the other.
Forms and scores
A shopping form may store your name as text, your age as a number and your agreement as yes or no. A game uses the same idea for names, scores and whether a door is open. Clear types help these systems avoid strange results.
Keep exploring
Other languages
Loading MyLeoNes™…