Standard built-ins

Math.abs()

Try the free JavaScript compiler

Absolute magnitude; converts -0 to +0. Converts x to Number; BigInt conversion throws TypeError.

Formal Syntax & Structure

javascript syntaxjavascript
Math.abs(x)

Parameters & Attributes

NameTypeDescription
xnumberNumber input or value coercible to Number.

Return Value

number

Result of the numerical operation, possibly NaN.

Working Example

Example Snippetjavascript
console.log(Math.abs(-8));
JavaScript Reference