JavaScript Math.abs()

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 »

Description

The Math.abs() method returns the absolute value of a number.




Syntax

Math.abs(x)

Parameters

Parameter Description
x Required.
A number.

Return Value

Type Description
NumberThe 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

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.