JavaScript sign() method
- Forrige side round()
- Næste side sin()
- Gå tilbage til forrige niveau 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, returns -1.
- If the number is zero, 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: |
Number, indicating the sign of the specified number:
|
---|---|
JavaScript version: | ECMAScript 2015 |
Browserstøtte
Metoder | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
sign() | 38.0 | 12.0 | 25.0 | 9.0 | 25.0 |
Relaterede sider
Tutorial:JavaScript matematik
- Forrige side round()
- Næste side sin()
- Gå tilbage til forrige niveau JavaScript Math Reference Manual