Math.abs( ) Method

Below is the example of the Math abs() method.

  • Example:

console.log(Math.abs(-22))
console.log(Math.abs(22)) 
  • Output

22
22

The Math.abs() method is used to return the absolute value of a number. It takes a number as its parameter and returns its absolute value.

Syntax:

Math.abs(value)

Parameters: This method accepts a single parameter as mentioned above and described below:

  • value: The number whose absolute value is to be found is passed as the parameter to this function.

Returns: Absolute value of the number passed as parameter.

Last updated