Convert a negative number to a positive one in JavaScript

Solution 1:

You could use this...

Math.abs(x)

Math​.abs() | MDN

Solution 2:

What about x *= -1? I like its simplicity.

Solution 3:

Math.abs(x) or if you are certain the value is negative before the conversion just prepend a regular minus sign: x = -x.