Math.abs()

Get the absolute value of a Number.

Signature

Math.abs(x: Number) => Number

Description

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

Parameters

Parameter Type Required Description

x

Number

true

Number for which you want the absolute value.

Return value

Type Description

Number

Absolute value of the provided number.

Examples

  1. Get the absolute value of an integer:

    Math.abs(5)
    5
  2. Get the absolute value of a negative integer:

    Math.abs(-5)
    5
  3. Get the absolution value of a real number:

    Math.abs(-5.1)
    5.1
\