JavaScript Math.sign() Method
The Math.sign() static method returns 1, -1 or 0 to show whether a number is positive, negative or zero.
Description
The Math.sign() static method returns the sign of a number: 1 if positive, -1 if negative and 0 (or -0) if zero. It's handy for directions, such as which way something is moving.
It distinguishes 0 from -0 by returning the same zero it was given, and returns NaN for values that can't be converted to numbers. Numeric strings are converted first.
Multiplying by the sign is a handy way to restore the direction of a value after working with its absolute value, as in Math.sign(x) * Math.min(Math.abs(x), limit), which caps a speed in either direction. Like every member of Math, it's called on the Math object itself rather than on a number, and it only works with the Number type: passing a BigInt throws a TypeError.
Syntax
Math.sign(x)Parameters
- xA number.
Return Value
1 for positive numbers, -1 for negative numbers, or 0 / -0 for zero.
Example
Browser Support
The following information will show you the current browser support for the Math.sign() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





