Others



JavaScript Math.abs()


The Math.abs(x) method used to finds the absolute value of the number.

Syntax
Math.abs(x)

Here, abs() is a static method. Hence, we use it as Math.abs().

Parameters
  • x - (Required).A number for which we want to compute the absolute value.
Return Value
  • The absolute value of the given number.
  • NaN - If the number is not within the range of -1 and 1.
Example
console.log(Math.abs(-50)); //50
console.log(Math.abs(50)); //50
console.log(Math.abs(null)); //0
console.log(Math.abs("hi")); //NaN
console.log(Math.abs()); //NaN
Try it Yourself

JavaScript Math Functions