デクリメント (--) - JavaScript | MDN
原題: Decrement (--) - JavaScript | MDN - MDN Web Docs
分析結果
- カテゴリ
- AI
- 重要度
- 54
- トレンドスコア
- 18
- 要約
- デクリメント演算子(--)は、JavaScriptにおいて数値を1減少させるための演算子です。この機能は広く利用可能で、多くのデバイスやブラウザバージョンで正常に動作します。デクリメント演算子は、前置形式(--x)と後置形式(x--)の2種類があり、それぞれ異なるタイミングで値を減少させます。
- キーワード
Decrement (--) - JavaScript | MDN Skip to main content Skip to search Decrement (--) 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. Learn more See full compatibility Report feedback The decrement ( -- ) operator decrements (subtracts one from) its operand and returns the value before or after the decrement, depending on where the operator is placed. Try it 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" Syntax js x-- --x Description The -- operator is overloaded for two types of operands: number and BigInt . It first coerces the operand to a numeric value and tests the type of it. It performs BigInt decrement if the operand becomes a BigInt; otherwise, it performs number decrement. If used postfix, with operator after operand (for example, x-- ), the decrement operator decrements and returns the value before decrementing. If used prefix, with operator before operand (for example, --x ), the decrement operator decrements and returns the value after decrementing. The decrement operator can only be applied on operands that are references (variables and object properties; i.e., valid assignment targets ). --x itself evaluates to a value, not a reference, so you cannot chain multiple decrement operators together. js --(--x); // SyntaxError: Invalid left-hand side expression in prefix operation Examples Postfix decrement js let x = 3; const y = x--; // x is 2; y is 3 let x2 = 3n; const y2 = x2--; // x2 is 2n; y2 is 3n Prefix decrement js let x = 3; const y = --x; // x is 2; y = 2 let x2 = 3n; const y2 = --x2; // x2 is 2n; y2 is 2n Specifications Specification ECMAScript® 2027 Language Specification # sec-postfix-decrement-operator Browser compatibility See also Addition ( + ) Subtraction ( - ) Division ( / ) Multiplication ( * ) Remainder ( % ) Exponentiation ( ** ) Increment ( ++ ) Unary negation ( - ) Unary plus ( + ) Help improve MDN Learn how to contribute This page was last modified on Jul 8, 2025 by MDN contributors . View this page on GitHub • Report a problem with this content