JavaScript (ES2026) reference · Math Methods and Constants
JavaScript Math.sign() Method
Return 1, -1 or 0 depending on whether a number is positive, negative or zero.
JavaScript (ES2026) Since ES2015
Syntax
Math.sign(x)
Parameters
| Parameter | Description |
|---|---|
x |
A number. |
Return value
1, -1, 0, -0 or NaN.
Examples
console.log(Math.sign(12), Math.sign(-3), Math.sign(0));
Output
1 -1 0
const change = -4.2;
console.log(["down", "flat", "up"][Math.sign(change) + 1]);
Output
down
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
Related
Math.abs()· Return the absolute value of a number: its distance from zero, so Math.abs(-5) is 5.- JavaScript Math · tutorial
- JavaScript Numbers · tutorial