Aller au contenu principal

Le site sera en maintenance le 01/03/2026

Aller au contenu principal

String Templates (Coucou les f-strings)

En Python, tu adores les f-strings : f"Salut {nom}". En JS, ça s'appelle les Template Literals.

Tu dois utiliser les backticks (l'accent grave `), souvent touche 7 ou AltGr+7.

const prenom = "James";
const nom = "Bond";

// JS (Backticks + ${})
const phrase = `Je m'appelle ${nom}, ${prenom} ${nom}.`;

// Python (f"")
// phrase = f"Je m'appelle {nom}, {prenom} {nom}."

Ça supporte aussi le multi-ligne sans prises de tête :

const html = `
    <div>
        <h1>Titre</h1>
        <p>Paragraphe</p>
    </div>
`;

C'est propre.