ES6 - Math sign() Function



Returns the sign of x.

Syntax

Math.sign( x ) ;     

Parameter

  • X − represents a number

Return Value

Returns -1 if x is negative; 1 if x is positive;0 if x is 0

Example

console.log("---Math.sign()---") 
console.log("Math.sign(-10.5) : "+Math.sign(-10.5)) 
console.log("Math.sign(6.77) : "+Math.sign(6.77))          

Output

---Math.sign()--- 
Math.sign(-10.5) : -1 
Math.sign(6.77) : 1           
Advertisements