--- title: Incrémentation (++) slug: Web/JavaScript/Reference/Operators/Increment tags: - JavaScript - Language feature - Operator - Reference browser-compat: javascript.operators.increment translation_of: Web/JavaScript/Reference/Operators/Increment ---
{{jsSidebar("Operators")}}

L'opérateur d'incrémentation (++) permet d'incrémenter (c'est-à-dire d'ajouter un) à son opérande et de renvoyer une valeur qui est le résultat avant ou après la modification.

{{EmbedInteractiveExample("pages/js/expressions-increment.html")}}

Syntaxe

Opérateur : x++ ou ++x

Description

Utilisé comme suffixe (l'opérateur étant placé après l'opérande), comme dans x++, l'opérateur incrémentera la valeur et renverra la valeur avant l'incrément.

Utilisé comme préfixe (l'opérateur étant placé avant l'opérande), comme dans ++x, l'opérateur incrémentera la valeur et renverra la valeur après l'incrément.

Exemples

Incrément en suffixe

let x = 3;
let y = x++;

// y = 3
// x = 4

Incrément en préfixe

let a = 2;
let b = ++a;

// a = 3
// b = 3

Spécifications

{{Specifications}}

Compatibilité des navigateurs

{{Compat}}

Voir aussi