This page was translated from English by the community.Learn more and join the MDN Web Docs community.
Math.sign()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 9월.
Math.sign() 함수는 주어진 수의 부호를 나타내는 +/-1을 반환합니다. 단,Math.sign()에 제공한 수가 0일 경우 부호에 따라 +/-0을 반환합니다.
In this article
시도해 보기
console.log(Math.sign(3));// Expected output: 1console.log(Math.sign(-3));// Expected output: -1console.log(Math.sign(0));// Expected output: 0console.log(Math.sign("-3"));// Expected output: -1구문
js
Math.sign(x);매개변수
x숫자.
number자료형이 아닐 경우 자동으로 변환합니다.
반환 값
주어진 값의 부호를 나타내는 수.
- 값이 양의 수일 경우
1을 반환합니다. - 값이 음의 수일 경우
-1을 반환합니다. - 값이 양의 0일 경우
0을 반환합니다. - 값이 음의 0일 경우
-0을 반환합니다. - 이외의 경우
NaN을 반환합니다.
설명
sign()은Math의 정적 메서드이므로, 사용자가 생성한Math 객체의 메서드가 아니라Math.sign()으로 호출해야 합니다. (Math는 생성자가 아닙니다)
예제
>Math.sign() 사용하기
js
Math.sign(3); // 1Math.sign(-3); // -1Math.sign("-3"); // -1Math.sign(0); // 0Math.sign(-0); // -0Math.sign(NaN); // NaNMath.sign("foo"); // NaNMath.sign(); // NaN명세서
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-math.sign> |