JavaScript sign() Method
- Previous Page round()
- Next Page sin()
- Go to the Previous Level JavaScript Math Reference Manual
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)
Syntax
Math.sign(x)
Parameter Value
Parameter | Description |
---|---|
x | Required. Number. |
Technical Details
Return value: |
Numeric value, indicating the sign of the specified number:
|
---|---|
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
- Previous Page round()
- Next Page sin()
- Go to the Previous Level JavaScript Math Reference Manual