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 square, but I also know that it is terribly inefficient.
x = -25 x = x * xx = sqrt(x)
Is there a way in JavaScript to simply abandon the sign of a number, which is more efficient than a mathematical approach?
javascript
Dan Walmsley Feb 19 '12 at 22:32 2012-02-19 22:32
source share