JavaScript, with a spell-checker
In JavaScript, "5" + 1 quietly becomes "51", and calling a function with the wrong thing only fails when that line runs — maybe in front of a user. TypeScript is JavaScript plus types: you describe what kind of value goes where, and it warns you about mistakes *while you type*.
Your first type
let price: number = 180;
price = "free";
function double(n: number) {
return n * 2;
}
console.log(double(21));
console.log(double("21"));- TypeScript files end in .ts. Browsers can't run them directly — they're compiled to plain JavaScript first, and the types are removed.
- Types cost nothing at runtime. They exist only to help you while you write.
- Every JavaScript program is (almost) valid TypeScript, so you can adopt it gradually.
In Sikau, TypeScript lessons type-check your code in strict mode — the setting professionals use.