BeCuriouzLearn something new every day
Why TypeScript? Catching Bugs Before They Run
💡 TypeScript is JavaScript with a static type checker that catches whole classes of bugs at compile time, before your code ever runs.
TypeScript is not a brand-new language — it's JavaScript plus static types. Every valid .js file is already valid TypeScript. What you add on top is type annotations: small notes that tell the compiler what kind of value each variable, parameter, and return should hold. Before your code ever runs, a type checker reads those notes and flags anything that doesn't add up.
Why does that matter? In plain JavaScript, mistakes only surface at runtime — when a user (or you) actually hits the broken line. TypeScript shifts that discovery earlier, to compile time, so the error shows up in your editor while you type instead of in production. Consider a function that expects a number:
function double(n: number): number {
return n * 2;
}
double("5"); // ❌ Error: Argument of type 'string'
// is not assignable to parameter of type 'number'In JavaScript, double("5") silently returns "55" (string repetition-ish surprises) or NaN depending on the operation — a bug you'd only notice later. TypeScript refuses to compile it. Crucially, the types are erased before the code runs: the browser or Node still executes ordinary JavaScript. TypeScript is a checking layer, not a runtime cost — it makes your JavaScript safer without changing what actually ships.