TypeScript · Lesson 7 of 120
Basic Types
String, number, boolean.
Most values are one of three basic types. Strings hold text. Numbers hold any number, whole or decimal. And booleans hold true or false.

- string: text
- number: any number
- boolean: true or false
The three basics
Model is a string, price is a number with decimals, and in stock is a boolean. Methods follow the type. Strings can be upper cased, numbers can be rounded to two decimals. Run it.
app.tstypescript
const model: string = "Trail 500";
const price: number = 849.5;
const inStock: boolean = true;
console.log(model.toUpperCase());
console.log(price.toFixed(2));
console.log(inStock ? "Available" : "Sold out");Output
TRAIL 500 849.50 Available
Methods follow the type
Because price is a number, TypeScript knows it has no upper case method. Run it. An error, before the program could crash.
app.tstypescript
const price: number = 849.5;
console.log(price.toUpperCase());Output
app.ts line 2: Property 'toUpperCase' does not exist on type 'number'.
Summary
Strings, numbers, and booleans are the basic types, and each has its own methods. Next, arrays.
Key takeaways- string
- number
- boolean
Next up: Arrays — lists of one type