Math abs() method
JavaScript Math abs() method
Last Updated : 17 Mar 2025
The JavaScript math abs() method returns an absolute value of a given number. The abs() is a static method of Math.
Syntax
The abs() method is represented by the following syntax:
Parameter
num - A number.
Return
An absolute value of a number.
JavaScript Math abs() method example
Here, we will understand abs() method through various examples.
Example 1
Let's see an example to print the absolute value of a number.
Output:
Example 2
Let's see some cases where abs() method returns 0.
Output:
Example 3
Let's see some cases where abs() method returns NaN.
Output:
Example 4
Let's understand the abs() method with your own test cases.