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, b
Alternative solution
Math.max(x,-x)
let abs = x => Math.max(x,-x); console.log( abs(24), abs(-24) );
Also the Rick answer can be shorted to x>0 ? x : -x
x>0 ? x : -x