Why Types Help
Catch bugs early.
Imagine a shop that adds delivery to a price. In JavaScript, if the price arrives as text, the plus sign glues the two together, instead of adding them. No error, just a wrong total.

- Price as text
- Plus glues them
- A silent bug
A silent JavaScript bug
Here the price is text, by mistake, and we add a delivery cost of five. This file is plain JavaScript, so nothing checks it. Run it. Twenty five? No, two hundred and five. The text and the number were glued together.
const price = "20"; // oops: text, not a number
const delivery = 5;
console.log("Total:", price + delivery);Total: 205
TypeScript catches it
In TypeScript, we say the total must be a number. Now the compiler checks the code before it runs. Run it. A type error, pointing at the exact line, before any customer sees a wrong price.
const price = "20";
const delivery = 5;
const total: number = price + delivery;
console.log("Total:", total);app.ts line 3: Type 'string' is not assignable to type 'number'.
What types give you
Mistakes are caught early, while you type. Your editor can suggest names, and show what each function needs. And big codebases become much easier to change safely.
| key | value |
|---|---|
| Bugs | caught early |
| Editor | smart suggestions |
| Changes | safe refactors |
| Teams | clear contracts |
Summary
Types catch mistakes like text plus number, before the code runs. Next, how TypeScript actually runs.
Key takeaways- Silent bugs
- Caught early
- Better editors