🔤TypeScript
Also known as TS
JavaScript with types added. It catches lots of mistakes before the code runs.
Think of it like
Think of it like labels on kitchen jars. The labels stop you putting salt in the sugar jar.
Example
Microsoft made TypeScript, and its VS Code editor is written in it. Jack types "twelve" where a number goes, and the line turns red.
Why it matters
Big JavaScript projects get hard to change safely. Types let the editor point out what a change will break.
Definition
Example code
typescript
let age: number = "twelve";
// error TS2322: Type 'string' is not assignable to type 'number'.Common mistake
Key takeaways
- 1JavaScript plus types. Every JavaScript file is almost valid TypeScript.
- 2Checked early. Mistakes show up as you type.
- 3Runs as JavaScript. A tool strips the types away.