Basic Types
Master the primitive and fundamental types
10-15 min
Basic Types in TypeScript
TypeScript provides several primitive types that form the foundation of its type system. Understanding these types is essential to using TypeScript effectively.
Primitive Types
1. string
The string type represents text strings:
let nom: string = "Alice";
let message: string = `Bonjour ${nom}`;
let description: string = 'Développeuse TypeScript';
// Template literals
let html: string = `
<div>
<h1>${nom}</h1>
<p>${description}</p>
</div>
`;
2. number
The number type represents all numbers (integers and decimals):
let age: number = 25;
let prix: number = 19.99;
let hexadecimal: number = 0xf00d;
let binaire: number = 0b1010;
let octal: number = 0o744;
// Opérations mathématiques
let total: number = prix * 2;
let moyenne: number = (10 + 20 + 30) / 3;
3. boolean
The boolean type represents true or false values:
let estActif: boolean = true;
let estComplete: boolean = false;
// Résultat d'expressions
let estMajeur: boolean = age >= 18;
let aAcces: boolean = estActif && estMajeur;
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion