--- title: Affectation après addition (+=) slug: Web/JavaScript/Reference/Operators/Addition_assignment tags: - Assignment operator - JavaScript - Language feature - Operator - Reference translation-of: Web/JavaScript/Reference/Operators/Addition_assignment browser-compat: javascript.operators.addition_assignment ---
L'opérateur d'addition et d'affectation (+=
) calcule la somme ou la concaténation de ses deux opérandes puis affecte le résultat à la variable représentée par l'opérande gauche. C'est le type des opérandes qui détermine s'il y a somme ou concaténation.
Opérateur : x += y Signification : x = x + y
let toto = "toto"; let truc = 5; let machin = true; // nombre + nombre -> addition truc += 2; // 7 // booléen + nombre -> addition machin += 1; // 2 // booléen + booléen -> addition machin += false; // 1 // nombre + chaîne de caractères -> concaténation truc += 'toto'; // "5toto" // chaîne de caractères + booléen -> concaténation toto += false // "totofalse" // chaîne de caractères + chaîne de caractères -> concaténation toto += 'truc' // "tototruc"
{{Specifications}}
{{Compat}}