Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Math.abs Function (JavaScript)

Returns the absolute value of a number.


The required number argument is a numeric expression for which the absolute value is needed.

The return value is the absolute value of the number argument.

The following example illustrates the use of the abs function.

function ComparePosNegVal(n)
   var s;
   var v1 = Math.abs(n);
   var v2 = Math.abs(-n);
   if (v1 == v2)
      s = "The absolute values of " + n + " and "
      s += -n + " are identical.";

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.

Applies To: Math Object (JavaScript)

Community Additions

© 2015 Microsoft