Favorites

JavaScript Math.sign() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math.sign()
JavaScript Math Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The Math.sign() static method returns 1, -1 or 0 to show whether a number is positive, negative or zero.

Description

The Math.sign() static method returns the sign of a number: 1 if positive, -1 if negative and 0 (or -0) if zero. It's handy for directions, such as which way something is moving.

It distinguishes 0 from -0 by returning the same zero it was given, and returns NaN for values that can't be converted to numbers. Numeric strings are converted first.

Multiplying by the sign is a handy way to restore the direction of a value after working with its absolute value, as in Math.sign(x) * Math.min(Math.abs(x), limit), which caps a speed in either direction. Like every member of Math, it's called on the Math object itself rather than on a number, and it only works with the Number type: passing a BigInt throws a TypeError.

Syntax

Math.sign(x)

Parameters

  • xA number.

Return Value

1 for positive numbers, -1 for negative numbers, or 0 / -0 for zero.

Example

console.log(Math.sign(42), Math.sign(-3), Math.sign(0));
const delta = -15;
console.log(Math.sign(delta) > 0 ? 'up' : 'down');

Browser Support

The following information will show you the current browser support for the Math.sign() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee