JavaScript sign() Method
Example
Find out if 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 »
Definition and Usage
The sign()
method checks whether a 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.
Browser Support
Method | |||||
---|---|---|---|---|---|
sign() | 38.0 | 12.0 | 25.0 | 9.0 | 25.0 |
Syntax
Math.sign(x)
Parameter Values
Parameter | Description |
---|---|
x | Required. A number |
Technical Details
Return Value: | A Number, representing the sign of the specified number:
|
---|---|
JavaScript Version: | ECMAScript 2015 |