Unit 1 · Module 4
Enter TypeScript
JavaScript with a safety net
Why TypeScript exists
JavaScript was never meant to run entire applications. It was built for small moments — make a button do something, add a little animation, respond to a click. That was it.
But the web grew. Companies started building enormous, complex apps entirely in JavaScript — banking platforms, collaboration tools, full business systems. And JavaScript, being the permissive language it is, had no way to protect you from yourself at that scale.
Here's how it would bite you. Say you wrote a function to calculate a total price:
A simple function
function calculateTotal(price, quantity) {
return price * quantity
} JavaScript doesn't care what you pass in. Two numbers? Works perfectly. A word and a number? JavaScript just tries. It won't stop you, won't warn you. It'll either give you a wrong answer silently — or crash in production, in front of a real user.
TypeScript was invented to put a checkpoint before that happens. Not to replace JavaScript. Just to stand at the door and ask: what exactly are you passing in there?
What a type actually is
A type is a label that describes what kind of value something is allowed to be.
That's the whole definition. There are five basic ones:
string— text. Anything in quotes."Ruthnie","golden retriever","hello"number— any number.42,3.99,0boolean— only ever two possible values.trueorfalsenull— intentionally empty. Someone set this to nothing on purposeundefined— accidentally empty. Nobody set this yet
These five cover the majority of what you'll encounter. Everything else TypeScript does is built on combinations of these.