インクリメント (++)
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.
Please take two minutes to fill out our short survey.
インクリメント演算子 (++
) は、オペランドをインクリメント (1 を加算) して値を返します。
試してみましょう
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"
構文
js
x++;
++x;
解説
オペランドに後置で演算子を付けると (例えば、 x++
) 、インクリメント演算子はインクリメントしますが、インクリメント前の値を返します。
オペランドに前置で演算子を付けると (例えば、 ++x
) 、インクリメント演算子はインクリメントし、インクリメント後の値を返します。
例
後置インクリメント
js
let x = 3;
y = x++;
// y = 3
// x = 4
前置インクリメント
js
let a = 2;
b = ++a;
// a = 3
// b = 3
仕様書
Specification |
---|
ECMAScript® 2026 Language Specification # sec-postfix-increment-operator |