97
JavaScript Math abs() method
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:
4 7.8 4
Example 2
Let’s see some cases where abs() method returns 0.
Output:
0 0 0
Example 3
Let’s see some cases where abs() method returns NaN.
Output:
NaN NaN NaN
Example 4
Let’s understand the abs() method with your own test cases.
Next TopicJavaScript Math