What is TypeScript?
TypeScript is a superset of JavaScript that adds a static type system. All valid JavaScript is valid TypeScript, but TS lets you annotate the types to catch errors before running.
Note: the browser doesn't understand TS directly; a compiler translates it to JavaScript. Types only exist while you write and compile.
Why use types?
- Catch errors earlier: passing a string where a number is expected fails at compile time, not in production.
- Better autocomplete: the editor knows which properties and methods exist.
- Living documentation: types explain what each function expects and returns.
Basic types
let age: number = 30;
let name: string = "Ana";
let active: boolean = true;
let tags: string[] = ["js", "ts"];
let anything: any = "whatever"; // avoid it when you can
Often you don't need to annotate: TypeScript infers the type from the value.
let total = 42; // TS deduces that total is number
// total = "hi"; // ❌ Error: you can't assign string to number
In this course
The exercise editor runs plain JavaScript. In the lessons you'll see type syntax to learn the concept, but in the exercises you'll write the logic in regular JS.
Examples
The same logic works in JS (without types)
let age = 30;
let name = "Ana";
let active = true;
console.log(typeof age, typeof name, typeof active);