I want to get the absolute value of a number in JavaScript. That is, drop the sign. I know mathematically I can do this by squaring the number then taking the square root, but I also know that this is horribly inefficient.
x = -25
x = x * x
x = Math.sqrt(x)
console.log(x)
Is there a way in JavaScript to simply drop the sign of a number that is more efficient than the mathematical approach?