From http://www.w3schools.com (Copyright Refsnes Data)

JavaScript abs() Method


Math Object Reference JavaScript Math Object

Definition and Usage

The abs() method returns the absolute value of a number.

Syntax

Math.abs(x)

Parameter Description
x Required. Must be a numeric value


Example

Example

Get the absolute values of positive and negative numbers:

<script type="text/javascript">

document.write(Math.abs(7.25) + "<br />");
document.write(Math.abs(-7.25) + "<br />");
document.write(Math.abs(7.25-10));

</script>

The output of the code above will be:

7.25
7.25
2.75

Try it yourself »


Math Object Reference JavaScript Math Object

From http://www.w3schools.com (Copyright Refsnes Data)