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 September 2015.
TheMath.sign() static method returns 1 or -1, indicating the sign of the number passed as argument. If the input is 0 or -0, it will be returned as-is.
In this article
Try it
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: -1Syntax
js
Math.sign(x)Parameters
xA number.
Return value
A number representing the sign ofx:
- If
xis positive, returns1. - If
xis negative, returns-1. - If
xis positive zero, returns0. - If
xis negative zero, returns-0. - Otherwise, returns
NaN.
Description
Becausesign() is a static method ofMath, you always use it asMath.sign(), rather than as a method of aMath object you created (Math is not a constructor).
Examples
>Using 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(); // NaNSpecifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-math.sign> |