TypeScript vs JavaScript
What TypeScript adds on top of JavaScript, what it costs, and when the trade-off is worth it.
2 min read
TypeScript isn't a competing language you choose instead of JavaScript — it's JavaScript plus a type system, compiled away before your code ships. Still, adopting it is a real decision with real trade-offs, and it's worth being clear-eyed about both sides.
What TypeScript adds
// JavaScript -- runs, but silently wrong if `price` is a string
function applyDiscount(price, percent) {
return price - price * (percent / 100);
}
// TypeScript -- the same mistake is caught before the code ever runs
function applyDiscount(price: number, percent: number): number {
return price - price * (percent / 100);
}
applyDiscount("19.99", 10); // compile error in TypeScript, silent bug in JavaScriptBeyond catching type mismatches, TypeScript's type information powers much richer editor tooling: accurate autocomplete on a function's parameters, inline errors as you type instead of only at runtime, and safe automated refactoring (renaming a property and having the editor find every real usage, not just every string that happens to match).
What it costs
- A build step. TypeScript has to be compiled to JavaScript before it runs anywhere — plain
.jsfiles don't need this. - More upfront writing. Function signatures, object shapes, and generic parameters all need to be described, which is more typing than the equivalent untyped JavaScript.
- A learning curve. Beyond basic annotations, real-world TypeScript involves generics, union types, and utility types (all covered later in this course) that take time to get comfortable with.
- Imperfect coverage at the edges. Data crossing a real boundary — a network response,
localStorage, user input — has no type until you tell TypeScript what to expect, and if you get that description wrong, TypeScript won't catch it; it can only check consistency with what you told it.
Where each one fits
Plain JavaScript is still the pragmatic choice for a quick script, a small prototype, or a one-off tool where the ceremony of typing everything doesn't pay for itself. TypeScript earns its cost on anything that will be read, changed, and extended by more than one person over time — which describes most production codebases, and is exactly why the large majority of professional frontend and Node.js projects default to it today.
They share the same language underneath
Since TypeScript is JavaScript with types layered on top, everything covered in the JavaScript course — closures, this, promises, array methods, the DOM — applies completely unchanged in TypeScript. Nothing here replaces that knowledge; this course adds a type system on top of it.
The next lesson gets hands-on: installing the TypeScript compiler and compiling your first .ts file.