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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Math.sign(x)

Parameters

ParameterDescription
x A number.

Return value

1, -1, 0, -0 or NaN.

Examples

Positive, negative, zeroTry it yourself
console.log(Math.sign(12), Math.sign(-3), Math.sign(0));

Output

1 -1 0
Pick a label from the signTry it yourself
const change = -4.2;
console.log(["down", "flat", "up"][Math.sign(change) + 1]);

Output

down

Version history

VersionChange
JavaScript ES2015Added

Was this page helpful?