Skip to main content
Version: 3.13.0

Math.abs()

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

Syntax

Math.abs(x)

Parameters

  • x
    • : A number.

Return value

The absolute value of x. If x is negative (including -0), returns -x. Otherwise, returns x. The result is therefore always a positive number or 0.

Description

Because abs() is a static method of Math, you always use it as Math.abs(), rather than as a method of a Math object you created (Math is not a constructor).