📚 Cheatsheet

Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.

Snippets 7

Retour
Définir un type de fonction
Intermédiaire
let maFonction: (a: number, b: number) => number;
Fonction avec des arguments typés
Facile
function addition(a: number, b: number) {
    return a + b;
}
Fonction avec un type de retour
Facile
function addition(a: number, b: number): number {
    return a + b;
}
Fonction fléchée
Facile
const multiplier = (a: number, b: number): number => a * b;
Paramètre optionnel
Facile
function construireNom(prenom: string, nom?: string) {
    // ...
}
Paramètre par défaut
Facile
function construireNom(prenom: string, nom = "Smith") {
    // ...
}
Paramètres du reste (Rest Parameters)
Intermédiaire
function construireNom(prenom: string, ...autresNoms: string[]) {
    return prenom + " " + autresNoms.join(" ");
}