Open In App

JavaScript Math abs() Method

Javascript Math.abs() method is used to return the absolute value of a number. It takes a number as its parameter and returns its absolute value.

Syntax:



Math.abs(value)

Parameters: This method accepts a single parameter as mentioned above and described below:

Returns: Absolute value of the number passed as a parameter. The below examples illustrate the Math abs( ) method in JavaScript:



Below is an example of the Math abs() method.

Example 1: This example shows the use of the Math.abs() method in javascript.




console.log(Math.abs(2));
console.log(Math.abs(2.56));

Output
2
2.56

Example 2: This example shows the return value of Math.abs() method when the parameter is a string value.




console.log(Math.abs("Geeksforgeeks"));

Output
NaN

Example 3: This example shows the return value of Math.abs() method when the parameter is an arithmetic expression.




console.log(Math.abs(7+9));

Output
16

Errors and Exceptions:

We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.

Supported Browsers:


Article Tags :