TypeScript vs JavaScript

Side by Side

JavaScriptTypeScript
Typingdynamic: types are checked while runningstatic: types are checked before running
Errors foundat runtime, often by usersin the editor and at build time
File extension.js, .jsx.ts, .tsx
Runs directly in browser / Nodeyesno, compiled to JS first (Node 22+ can strip simple types)
Refactoring large coderiskysafe: the compiler shows every place to fix
Learning curvesmallera little more to learn, pays off in big projects

The Classic JavaScript Bug

In JavaScript, "5" + 10 gives "510", not 15. Such bugs reach production because nothing checks them. TypeScript makes the intent clear.

Example

The function says it wants numbers. Calling it with a string from a form field is now a compile error, so you are forced to convert it first.

function addToCart(currentTotal: number, price: number): number {
  return currentTotal + price;
}

const priceFromForm = "499"; // values from inputs are strings
console.log(addToCart(1000, Number(priceFromForm)));
console.log(addToCart(1000, parseFloat("99.5")));

Output

1499
1099.5

Typos in Property Names

Example

A misspelled property silently gives undefined in JavaScript. TypeScript reports TS2551 and even suggests the right name.

const product = { name: "Wireless Mouse", price: 799 };

console.log(product.prise);

Compiler output (tsc)

Line 3: error TS2551: Property 'prise' does not exist on type '{ name: string; price: number; }'. Did you mean 'price'?