A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Operators/Addition_assignment below:

Affectation après addition (+=) - JavaScript

Affectation après addition (+=)

Baseline Widely available

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.

Exemple interactif
let a = 2;
let b = "hello";

console.log((a += 3)); // Addition
// Expected output: 5

console.log((b += " world")); // Concatenation
// Expected output: "hello world"
Syntaxe
Opérateur: x += y;
Signification: x = x + y;
Exemples Utiliser l'opérateur d'addition et d'affectation
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"
Spécifications Compatibilité des navigateurs Voir aussi

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4