Make number negative in JavaScript

There are two simple solutions:

1. Use -Math.abs().

-Math.abs(number);

2. Multiply the number by -1 if it’s positive.

if(number >= 0) {
  number = number * -1;
}

Example:

Convert a number to negative.

<script>
  var myNumber = 15;
  myNumber = -Math.abs(myNumber);

  console.log(myNumber);
</script>

Output: -15

Example 2:

<script>
  var myNumber = 2;

  if(myNumber >= 0) {
    myNumber = myNumber * -1;
  }
  
  console.log(myNumber);
</script>

Output: -2