デクリメント (--)
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.
デクリメント演算子 (--
) は、オペランドをデクリメント (1 を減算) して値を返します。
試してみましょう
let x = 3;
const y = x--;
console.log(`x:${x}, y:${y}`);
// Expected output: "x:2, y:3"
let a = 3;
const b = --a;
console.log(`a:${a}, b:${b}`);
// Expected output: "a:2, b:2"
構文
js
x--;
--x;
解説
オペランドに後置で演算子を付けると (例えば x--
)、デクリメント演算子はデクリメントしますが、デクリメント前の値を返します。
オペランドに前置で演算子を付けると (例えば --x
)、デクリメント演算子はデクリメントし、デクリメント後の値を返します。
例
後置デクリメント
js
let x = 3;
y = x--;
// y = 3
// x = 2
前置デクリメント
js
let a = 2;
b = --a;
// a = 1
// b = 1
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-postfix-decrement-operator |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Decrement ( -- ) |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.