Incrémentation (++)

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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.

Exemple interactif

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

console.log(`x:${x}, y:${y}`);
// Expected output: "x:4, y:3"

let a = 3;
const b = ++a;

console.log(`a:${a}, b:${b}`);
// Expected output: "a:4, b:4"

Syntaxe

js
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

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

// y = 3
// x = 4

Incrément en préfixe

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

// a = 3
// b = 3

Spécifications

Specification
ECMAScript® 2025 Language Specification
# sec-postfix-increment-operator

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
Increment (++)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi