ES6 - Math.sign()


Advertisements

This function returns the sign of a number, indicating whether the number is positive, negative or zero.

Syntax

The syntax mentioned herewith is for the function Math.sign(), where, X − represents a number.

Math.sign( x ) ;

Example

<script>
   console.log(Math.sign(-Infinity)) // console.log(Math.sign(-10)) // -1
   console.log(Math.sign(0)) // 0
   console.log(Math.sign(Infinity)) // 1
   console.log(Math.sign(10)) // 1
   console.log(Math.sign('N')) // NaN
</script>

The output of the above code will be as given below −

-1
0
1
1
NaN
Advertisements