72
JavaScript Math sign() method
The JavaScript math sign() method returns the sign of the number. It indicates whether the given number is positive, negative or zero.
Syntax
The sign() method is represented by the following syntax:
Parameter
num – A number.
Return
The sign of the given number.
JavaScript Math sign() method example
Here, we will understand sign() method through various examples.
Example 1
Let’s see an example to find out the sign of the given number.
Output:
1 -1 0
Example 2
Let’s see some cases where sign() method returns NaN.
Output:
NaN NaN NaN
Example 3
Here, you can test sign() method with your own test cases.
Next TopicJavaScript Math