Math.sign()
The Math.sign()
function 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.
Syntax
Math.sign(x)
Parameters
x
- : A number.
Return value
A number representing the sign of x
:
- If
x
is positive, returns1
. - If
x
is negative, returns-1
. - If
x
is positive zero, returns0
. - If
x
is negative zero, returns-0
. - Otherwise, returns
NaN
.
Description
Because sign()
is a static method of Math
, you always use it as Math.sign()
, rather than as a method of a Math
object you created (Math
is not a constructor).