Math.abs() Function
What is the use of Math.abs() method in Javascript?
How to get the absolute value of an number in javascript?
Explanation
Object:
MathMethod:
Math.abs()Description:This function is used to get the absolute value of a number.
Example:
<script type="text/javascript">
document.write('Absolute value of -4.23 is ::'+Math.abs(-4.23) + "<br/>");
document.write('Absolute value of null is ::'+Math.abs(null) + "<br/>");
</script>
Result:
In the above example,
- Absolute value of negative number gives a positive value whereas for a null value it is "0".