Sometimes, we want to convert positive number to negative number in JavaScript.
In this article, we’ll look at how to convert positive number to negative number in JavaScript.
How to convert positive number to negative number in JavaScript?
To convert positive number to negative number in JavaScript, we can use the -
operator.
For instance, we write
const n = -Math.abs(num);
to call Math.abs
with num
to get the absolute value of num
.
Then we use the unary -
operator to convert the absolute value to a negative number.
Conclusion
To convert positive number to negative number in JavaScript, we can use the -
operator.