Math in JavaScript is a built-in object that contains different methods and properties used to perform mathematical operations. It contains an abs() function, which is used to compute a specified number’s absolute value. Absolute value is the number without a sign.
Math.abs(param);
param: This is the input value of type Number for which we want to find the abs().
Numberin JavaScript is a 64-bit double-precision value which is the same asdoublein C# or Java.
Number: It returns the absolute value of the given param. If param is negative, it returns positive param, and returns the same if param is already positive.
NaN: The function returns NaN if param is one of the following:
0: The function returns this if param is one of the following:
console.log("abs('-1') = " + Math.abs('-1'));console.log("abs(-1) = " + Math.abs(-1));console.log("abs([1]) = " + Math.abs([-1]));console.log("abs('educative') = " + Math.abs('educative'));console.log("abs() = " + Math.abs());console.log("abs([1,-1]) = " + Math.abs([1,-1]));console.log("abs({}) = " + Math.abs({}));console.log("abs(null) = " + Math.abs(null));console.log("abs('') = " + Math.abs(''));console.log("abs([]) = " + Math.abs([]));