Portmint Lighthouse

Types, the Kinds of Values

Here is the plain idea: the values you store come in different kinds, and the computer treats each kind by its own rules. A number is not the same kind of thing as a piece of text, even when they look alike. These kinds are called types.

The three you'll meet first: numbers, text, and true-or-false.

The three starter types

A number is a quantity — 5, 30, 47.99. You can add, subtract, and multiply numbers, because arithmetic is what numbers are for.

Text is a run of characters — "hello", "Saratoga Springs", even "30". Programmers call a piece of text a string, because it's characters strung together like beads. You don't do arithmetic on text; you join it, search it, or measure its length.

A true-or-false value has exactly two possibilities: true or false. Programmers call this a boolean. It answers a yes-or-no question and nothing else: is the door locked? Is the user over 18?

The measuring-cup analogy

Think of your kitchen tools. A measuring cup is for liquids, a scale is for weight, a timer is for minutes. You could try to weigh water on a timer, but it makes no sense — each tool fits its own kind of thing.

Types work the same way. Each kind of value comes with the operations that make sense for it. Multiply two numbers — fine. Multiply two sentences — meaningless. The type tells the computer which tools apply.

Why the difference bites

Here's the trap that catches every beginner. The number 30 and the text "30" look identical on the page, but they are different types, and the computer treats them differently.

Add the numbers 30 + 30 and you get 60. "Add" the texts "30" + "30" and many languages glue them into "3030" — because joining is what you do to text. Same-looking characters, completely different result, all because of the type.

So when a value misbehaves, ask first: what type is this, really? A surprising number of bugs are just text wearing a number's costume.

Types keep you honest

You might think types are a nuisance. They're actually a guardrail. By insisting that a number is a number and text is text, the computer can catch mistakes early — like noticing you tried to do math on someone's name before it causes a mess downstream.

So: values come in kinds, each kind has its own rules and its own tools, and a lot of clarity comes from simply knowing which kind you're holding.

Your turn

No computer needed — just sort these by type. For each one, say whether it's a number, a string (text), or a boolean (true/false):

  • 42
  • "yes"
  • false
  • "42"
  • 19.95

Then answer the one that matters most: would "5" + "5" more likely give you 10 or "55"? Think about whether you're adding quantities or stringing beads together.

(Sorted: 42 and 19.95 are numbers, "yes" and "42" are strings, false is a boolean. And those quote marks make "5" + "5" text being joined — so you'd more likely get "55", not 10.)

Once you can tell the kinds apart, you're ready to put true-or-false values to work — that's how a program starts making decisions. 🔦

Stuck or curious?

Ask Pip about this lesson — tap the porthole bottom-right.