Math.abs()

Returns the absolute value of a number.

Since ES1 Spec ↗

Syntax

Math.abs(x)

Parameters

NameTypeRequiredDescription
x number Yes The number whose absolute value is returned.

Returns

number — The absolute value of x, or NaN if x is not numeric.

Examples

console.log(Math.abs(-5), Math.abs(5));
Output
5 5
console.log(Math.abs('abc'));
Output
NaN

Notes

Non-numeric arguments are coerced; uncoercible values yield NaN. `Math.abs(-0)` is 0.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also