What TypeScript is in TypeScript
Topic 1 of 37 · 8 minFree lessonJavaScript lets a lot of mistakes through. A misspelled name or a number used as text often shows up only when the program runs, sometimes in front of a user. TypeScript is JavaScript with types added. It reads your code before it runs and points out these mistakes, with the line they're on.
A type says what kind of value something is: a number, some text, a list of names. TypeScript works out the type of every value, then checks that each value is used in a way that makes sense.
A mistake caught before it runs
Here, price holds a number, but the code treats it like text. toUpperCase() is a method for strings, so numbers don't have it.
let price = 4;console.log(price.toUpperCase());Plain JavaScript would only find this when it reached line 2, and stop with an error there. TypeScript finds it without running anything. Each error has a number, like TS2339, and a message that says what's wrong.
TypeScript is still JavaScript
Everything you know from JavaScript still works. A program with no mistakes in it runs exactly as before.
const name = "Ada";const languages = ["Python", "JavaScript"];console.log(`${name} knows ${languages.length} languages.`);TypeScript only adds checks. When the program runs, the types are removed and what's left is plain JavaScript.
Your first type
You can write a type yourself, after the variable's name and a colon. This is called a type annotation. Here, : string says city must always hold text.
let city: string = "Lisbon";city = "Tokyo";console.log(city);Giving city a number later would be a mistake, and TypeScript would point it out. You'll meet the basic types in the next topic.
Seeing the types TypeScript works out
Often you don't need to write a type at all. TypeScript works it out from the value. In this course, a line with // ^? shows the type of what the ^ points at, on the line above.
const total = 4 * 3;// ^? const total: numberconsole.log(total);In a code editor like VS Code, you see the same thing by holding the mouse over a name.
How your code runs here
When you press Run, TypeScript checks your code first. If it finds a type error, it shows it, and the program doesn't run. Fix the error, run again, and your program runs as JavaScript. Real projects work the same way: a tool called tsc checks the code, then the JavaScript runs. Since TypeScript 7, released in July 2026, tsc is written in Go, another programming language, and checks big projects about ten times faster. The language itself hasn't changed.
undefined and carries on, which hides the bug. TypeScript knows the object's properties, so it stops you and even suggests the right name.const user = { name: "Ada", age: 36 };console.log(user.nme);Try it yourself
Run the code in the editor and answer 8 practice questions on what typescript is. It's free, you only need an account.