abs Function

Top  Previous  Next

Gets the absolute value of a number.

Syntax

Math.abs(number)

Arguments

integerA number.        

Return Value

The absolute value of the number, 0 if the argument is null.

Examples

Math.abs(null);    // Returns 0

Math.abs("Hello"); // Returns NaN

Math.abs(9.98);    // Returns 9.98

Math.abs(-7.25);   // Returns 7.25

Math.abs(-2);      // Returns 2