ES6 - Math Abs() Function


Advertisements

This method returns the absolute value of a number.

Syntax

Math.abs( x ) ;     

Parameter

  • X − represents a number

Return Value

Returns the absolute value of a number

Example

console.log("---Math.abs()---") 
console.log("Math.abs(-5.5) : "+Math.abs(-5.5)) 
console.log("Math.abs(5.5) : "+Math.abs(5.5))         

Output

---Math.abs()--- 
Math.abs(-5.5) : 5.5 
Math.abs(5.5) : 5.5          
es6_math.htm
Advertisements