TYPESCRIPT / LESSON 01
What is TypeScript?
Understanding why TypeScript exists and how it makes JavaScript safer

Loading the lesson…
Loading activities…
TYPESCRIPT / LESSON 01
Understanding why TypeScript exists and how it makes JavaScript safer

Loading the lesson…
Loading activities…
You ever fill out a form online and accidentally type your phone number into the email box? The form lights up red right away and says "Please enter a valid email." Annoying for half a second... but it just saved you from sending garbage.
TypeScript does that exact thing for your code. It catches mistakes BEFORE your program ever runs, so you're not finding out about a bug from a real user who's already mad about it.
JavaScript is super flexible. You can stick any value in any variable, pass anything into any function, and JavaScript will do its best to make it work anyway. Sounds great on paper. In practice it's how bugs sneak in.
Bugs like these can hide out until your app is live and real people are using it. That's a lousy way to find out.
TypeScript is a superset of JavaScript. Fancy phrase, simple meaning... every bit of valid JavaScript is also valid TypeScript. TypeScript just bolts on one big extra, and that's types.
Types tell the computer what kind of data a variable is supposed to hold, or what kind of data a function is expecting to get.
Here's the big idea. TypeScript checks your code before it runs. The errors show up in your editor while you type, instead of after your users trip over them.
Before I ever touched marketing I had an engineering career, and this is the part that clicked for me right away. Catching a problem on paper is WAY cheaper than catching it after the thing is built.
Browsers can't run TypeScript directly. Node.js is a different story now. Since Node 22.18 and 23.6 it'll run a .ts file straight up by stripping the types out on the fly (it doesn't check them though, and a few TypeScript-only features like enum won't run that way). For anything headed to a browser, and for actually catching your mistakes, the normal route is still a process called compilation that checks your TypeScript and turns it into regular JavaScript.
You write your code, types and all, in .ts files.
The TypeScript compiler reads through your code and looks for type errors.
TypeScript strips out the type annotations and spits out plain JavaScript that any browser can run. Heads up though... by default it'll still write out that JavaScript even when it found errors, so don't just ignore the red squiggles and hope for the best.
Think of it like a translator who proofreads too. It translates your typed code into JavaScript and flags the mistakes along the way.
TypeScript got REALLY popular, really fast. Here's why big companies like Microsoft, Google, Airbnb, and Stripe use it.
| Feature | JavaScript | TypeScript |
|---|---|---|
| File extension | .js | .ts |
| Type checking | No | Yes |
| Runs directly | Yes | In browsers no (compiles to JS). Newer Node.js strips the types and runs it |
| IDE support | Basic | Excellent |
| Learning curve | Lower | Slightly higher |
| Bug prevention | Runtime errors | Compile-time errors |
.ts files directly, minus the type checking)So now you know what TypeScript is and why it exists. Next up we get into the actual syntax... you'll learn how to write type annotations and meet the basic types TypeScript gives you.