Step 7 of 10 · F · Data types in code
Data types, in code
num
Remember the stamp? In code, programmers call this a data type.
Step 1 / 21recall
let score: number = 100;
console.log(score);Output
100
| Aspect | |||||
|---|---|---|---|---|---|
| Type visible in the line? | yes | yes | yes | no | optional |
| Type before name? | no | yes | yes | — | no |
| Type after name? | yes (: number) | no | no | — | yes (: int) |
Remember the stamp on the box? In code, that stamp is called a data type — or just type for short.
Some languages write the type right in the line of code. Others hide it.
In
ts, the type comes after the name, with a colon: let score: number = 100;.In
dart, the type comes before the name: int score = 100; reads left-to-right as number-box called score holding 100.In
php, the type can also come before the name when you choose to write one: int $score = 100;.In
js, no type is shown — the box is loose and accepts any family of value.A loose box is convenient at first, but can lead to surprises later — that is why typed languages exist.
In
py, the type is optional. You can write score: int = 100 as a hint, or just skip it.Where the type sits — before or after the name — is a style choice the language makes. The meaning is the same.
Languages that show the type can tell you about mistakes early — before the program even runs.
Languages that hide it run more freely, but trust you to keep things straight.
Check yourself
Match the pairs
Match each language to where it puts the **type**:
