Description:
Returns the absolute value of a number
Syntax:
Math.abs(number)
| Parameters | Description |
|---|---|
| number | Required. Any numeric expression |
Return Data Type:
Numeric
Usage / Example Code:
You can test it the following code using document.write() or alert() methods
| Statement | Result / Value | Remark / Note |
|---|---|---|
| Math.abs(1) | 1 | |
| Math.abs(123) | 123 | |
| Math.abs(45.678) | 45.678 | |
| Math.abs(-1) | 1 | |
| Math.abs(-123) | 123 | |
| Math.abs(-45.678) | 45.678 | |
| Math.abs(0) | 0 | |
| Math.abs(unknown) | Error | unknown is not defined (uninitialized variable) |
| Math.abs(initialized) | NaN | Not a Number |
| Math.abs(null) | 0 | |
| Math.abs(‘string’) | NaN | Not a Number |
| Math.abs(’45.678′) | 45.678 | |
| Math.abs(true) | 1 | |
| Math.abs(false) | 0 | |
| Math.abs() | NaN | Not a Number |
Related Articles:

