Math.sign()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

The Math.sign() static method 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.

Try it

Syntax

js
Math.sign(x)

Parameters

x

A number.

Return value

A number representing the sign of x:

  • If x is positive, returns 1.
  • If x is negative, returns -1.
  • If x is positive zero, returns 0.
  • 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).

Examples

Using Math.sign()

js
Math.sign(3); // 1
Math.sign(-3); // -1
Math.sign("-3"); // -1
Math.sign(0); // 0
Math.sign(-0); // -0
Math.sign(NaN); // NaN
Math.sign("foo"); // NaN
Math.sign(); // NaN

Specifications

Specification
ECMAScript Language Specification
# sec-math.sign

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
sign

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also