Latest

recent

JavaScript abs() Method

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

In this 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
JavaScript abs() Method Reviewed by 1000sourcecodes on 03:00 Rating: 5
Powered by Blogger.