--- title: 단항 부정 (-) slug: Web/JavaScript/Reference/Operators/Unary_negation tags: - JavaScript - Language feature - Operator - Reference browser-compat: javascript.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

명세

{{Specifications}}

브라우저 호환성

{{Compat}}

같이 보기