JavaScript(JS) math method - abs

The abs() method is a built-in function in JavaScript that is available on the Math object. It returns the absolute value of a number, which is the distance between the number and zero on a number line.

Here's an example that demonstrates how to use the abs() method:

console.log(Math.abs(-5)); // Output: 5
console.log(Math.abs(5)); // Output: 5
Source:w‮gi.ww‬iftidea.com

In the example above, the Math.abs() method is called on the numbers -5 and 5, which returns their absolute values, 5 and 5, respectively.

The abs() method is useful when you need to work with the distance between two numbers, regardless of their sign. For example, you can