Home » JavaScript Math sign() Method

JavaScript Math sign() Method

by Online Tutorials Library

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.

Test it Now

Output:

1  -1  0  

Example 2

Let’s see some cases where sign() method returns NaN.

Test it Now

Output:

NaN  NaN  NaN  

Example 3

Here, you can test sign() method with your own test cases.

Test it Now

Next TopicJavaScript Math

You may also like