Summary - Primitive types
- TypeScript course
- Beginner
- Lesson 10/89
- 4 min
Write a profile card by combining string, number, and boolean types.
The three primitive types
So far you have seen three primitive types: string for text, number for numbers (integer or decimal), and boolean for two-state logic. You also learned to declare variables with let and const.
let isim: string = "Ece";
let yas: number = 28;
let aktif: boolean = true;
const dil = "TypeScript";These four pieces are the foundation of TypeScript.
Practice Use the three types together
Declare three variables: urun (string, value "Kalem"), adet (number, value 3), stokta (boolean, value true). Print all three with a single console.log.
Starter code
// urun (string), adet (number), stokta (boolean) tanımla
// üçünü tek console.log ile yazdırSample solution
let urun: string = "Kalem";
let adet: number = 3;
let stokta: boolean = true;
console.log(urun, adet, stokta);Expected output
Kalem 3 true
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which of the following lines uses the correct types?
- let x: number = "5"; let y: string = a; let z: boolean = true;
- let x: int = 5; let y: string = "a"; let z: float = 3.14;
- let x: number = 5; let y: text = "a"; let z: bool = true;
- let x: number = 5; let y: string = "a"; let z: boolean = true; Correct answer
Explanation: number, string, and boolean are written lowercase; the values must also match the type.
2 Fill in the missing value
let tam: number = 42;
let metin: string = ____;
let dogru: boolean = true;
let tam: number = 42;
let metin: string = "kod";
let dogru: boolean = true;
Explanation: A string variable must be assigned a text value (in quotes); a word without quotes is treated as a variable, and 42 and true are different types.
3 Primitive types and keywords
| Term | Meaning |
|---|---|
string |
text type |
number |
numeric type |
boolean |
logical type |
const |
constant variable |