JavaScript Math.sign()
Definition and Usage
The Math.sign()
method retuns whether a number is negative, positive or zero.
If the number is positive, this method returns 1.
If the number is negative, it returns -1.
If the number is zero, it returns 0.
Browser Support
Math.sign()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
Math.sign()
is not supported in Internet Explorer 11 (or earlier).
Syntax
Math.sign(x)
Parameters
Parameter | Description |
---|---|
x | Required. A number. |
Return Value
A Number, representing the sign of the specified number:
|