단항 부정 (-)
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® 2026 Language Specification # sec-unary-minus-operator |