JavaScript sign() Method

Definition and Usage

sign() The method checks whether the number is negative, positive, or zero.

  • If the number is positive, this method returns 1.
  • If the number is negative, it returns -1.
  • If the number is zero, it returns 0.

Example

Determine whether a number is negative or positive:

var a = Math.sign(3);    // Returns 1 (positive)
var b = Math.sign(-3);   // Returns -1 (negative)
var c = Math.sign(0);    // Returns 0 (zero)

Try It Yourself

Syntax

Math.sign(x)

Parameter Value

Parameter Description
x Required. Number.

Technical Details

Return value:

Numeric value, indicating the sign of the specified number:

  • If the number is positive, it returns 1
  • If the number is negative, it returns -1
  • If the number is positive zero, it returns 0
  • If the number is negative zero, it returns -0
  • If it is not a number, it returns NaN
JavaScript Version: ECMAScript 2015

Browser Support

Method Chrome Edge Firefox Safari Opera
sign() 38.0 12.0 25.0 9.0 25.0

Related Pages

Tutorial:JavaScript Math