--- title: 単項マイナス (-) slug: Web/JavaScript/Reference/Operators/Unary_negation tags: - JavaScript - Language feature - Operator - Reference - 演算子 - 言語機能 translation_of: Web/JavaScript/Reference/Operators/Unary_negation ---
{{jsSidebar("Operators")}}

単項マイナス演算子 (-) はオペランドの前に置かれ、符号を反転します。

{{EmbedInteractiveExample("pages/js/expressions-unary-negation.html")}}

構文

演算子: -x

数値の符号を反転

const x = 3;
const y = -x;

// y = -3
// x = 3

数値以外の符号を反転

単項マイナス演算子は、数値でないものを数値に変換することができます。

const x = "4";
const y = -x;

// y = -4

仕様書

仕様書
{{SpecName('ESDraft', '#sec-unary-minus-operator', 'Unary negation operator')}}

ブラウザーの互換性

{{Compat("javascript.operators.unary_negation")}}

関連情報