pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Decrement

href="?u=http://developer.mozilla.org/static/client/inter-latin.9a3b1bc220d426ef.woff2" as="font" type="font/woff2" crossorigen="anonymous" fetchpriority="low" />

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

デクリメント演算子 (--)

Baseline 広く利用可能

この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。

デクリメント演算子 (--) は、オペランドをデクリメント(1 を減算)し、演算子が置かれている場所次第で、デクリメントの前または後の値を返します。

試してみましょう

let x = 3;
const y = x--;

console.log(`x:${x}, y:${y}`);
// 予想される結果: "x:2, y:3"

let a = 3;
const b = --a;

console.log(`a:${a}, b:${b}`);
// 予想される結果: "a:2, b:2"

構文

js
x--
--x

解説

-- 演算子は、数値と長整数の 2 種類のオペランドに対してオーバーロードされています。最初にオペランドを数値の値に変換し、その型を検査します。オペランドが長整数になった場合、長整数のデクリメントを実行し、そうでない場合は数値のデクリメントを実行します。

演算子をオペランドの後ろに付けて後置演算子として使用した場合(例えば x--)、デクリメント演算子はデクリメントを行い、デクリメント前の値を返します。

演算子をオペランドの前に付けて前置演算子として使用した場合(例えば --x)、デクリメント演算子はデクリメントを行い、デクリメント後の値を返します。

デクリメント演算子は、参照(変数やオブジェクトのプロパティ、つまり有効な代入対象)であるオペランドにのみ適用することができます。 --x 自体は値として評価され、参照ではないため、複数のデクリメント演算子を連結することはできません。

js
--(--x); // SyntaxError: Invalid left-hand side expression in prefix operation

後置デクリメント

js
let x = 3;
const y = x--;
// x は 2、y は 3

let x2 = 3n;
const y2 = x2--;
// x2 は 2n、y2 は 3n

前置デクリメント

js
let x = 3;
const y = --x;
// x は 2; y = 2

let x2 = 3n;
const y2 = --x2;
// x2 は 2n; y2 は 2n

仕様書

仕様書
ECMAScript® 2027 Language Specification
# sec-postfix-decrement-operator

ブラウザーの互換性

関連情報

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy