単項マイナス (-)
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.
単項マイナス演算子 (-
) はオペランドの前に置かれ、符号を反転します。
試してみましょう
const x = 4;
const y = -x;
console.log(y);
// Expected output: -4
const a = "4";
const b = -a;
console.log(b);
// Expected output: -4
構文
js
-x;
例
数値の符号を反転
js
const x = 3;
const y = -x;
// y = -3
// x = 3
数値以外の符号を反転
単項マイナス演算子は、数値でないものを数値に変換することができます。
js
const x = "4";
const y = -x;
// y = -4
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-unary-minus-operator |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Unary negation ( - ) |
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.