Foundations  ›  Lesson 1 of 13
Foundations

Why bother with types?

JavaScript runs whatever you give it. TypeScript stops to ask whether you meant it.

JavaScript is forgiving to a fault. Add a number to a string and it quietly makes a string. Call .toUpperCase() on something that turns out to be undefined at 2am in production, and you find out the hard way. TypeScript adds a layer on top of JavaScript — types — that describes the shape of your data up front, so a whole category of mistakes gets caught while you're typing, not after you've shipped.

Every TypeScript file compiles down to ordinary JavaScript. The types themselves never run — they exist purely to check your work, then vanish. That's the deal this whole course is about: you write a bit more up front, and in exchange the language tells you exactly where your assumptions don't hold.

A small example

Here's a function with one parameter explicitly typed as a number. Try changing the call at the bottom to pass a string instead, and watch what the checklist below says about it.

NoteThis playground runs a simplified version of TypeScript — it strips annotations and executes the JavaScript underneath, so it won't catch every real type error the way the actual compiler would. Treat it as a place to practice the syntax and see your code run.
playground.ts
Output
Run the code to see output here.
Checklist
Uses a type annotation on the parameter
Uses a return type annotation
Calling double(21) logs 42