JavaScript Math.abs()
❮
Math Object
❯
Definition and Usage
The Math.abs()
method returns the absolute value of a number.
More Examples
let a = Math.abs(7.25);
let b = Math.abs(-7.25);
let c = Math.abs(null);
let d = Math.abs("Hello");
let e = Math.abs(2-3);
Try it Yourself » Browser Support
Math.abs()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
Math.abs(x)
Parameters
Parameter | Description |
x | Required. A number. |
Return Value
A number representing the absolute value of the specified number. r NaN if the value is not a number. 0 if the value is null. |
❮
Math Object
❯