JavaScript Math.abs()
❮
Math Object
❯
Examples
let x = Math.abs(-7.25);
Try it Yourself »
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 »
Definition and Usage
The Math.abs()
method returns the absolute value of a number.
JavaScript Rounding Functions
The Math.abs() MethodThe Math.ceil() Method
The Math.floor() Method
The Math.round() Method
The Math.fround() Method
The Math.trunc() Method
Syntax
Math.abs(x)
Parameters
Parameter | Description |
x | Required. A number. |
Return Value
Type | Description |
Number | The absolute value of the number.NaN if the value is not a number.0 if the value is null . |
Browser Support
Math.abs()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
❮
Math Object
❯