JavaScript sign() method
- Föregående sida round()
- Nästa sida sin()
- Åter till föregående nivå JavaScript Math referenshandbok
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: |
Value, indicating the sign of the specified number:
|
---|---|
JavaScript version: | ECMAScript 2015 |
Webbläsarstöd
Metoder | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
sign() | 38.0 | 12.0 | 25.0 | 9.0 | 25.0 |
Relaterade sidor
Tillämpning:JavaScript matematik
- Föregående sida round()
- Nästa sida sin()
- Åter till föregående nivå JavaScript Math referenshandbok