This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
In this article, you will learn how to convert a positive number into a negative number in Javascript.
Let’s say you have a number variable called ‘a’ with value 123.
var a = 123;
In order to convert a positive number into a negative number, you can use the unary negation operator -
.
var a = 123;
console.log(-a);
Note: The unary negation operator -
functions by converting any value on its right side into a number and negates it.
The post How to Convert A Positive Number Into A Negative Number in Javascript appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-02-17T07:32:26+00:00) How to Convert A Positive Number Into A Negative Number in Javascript. Retrieved from https://www.scien.cx/2021/02/17/how-to-convert-a-positive-number-into-a-negative-number-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.