単項マイナス (-)

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 GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
Unary negation (-)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報