Negative numbers in JavaScript

Numbers can be negative. To do this, put a minus sign before the number:

let a = -1; alert(a); // shows -1

A minus sign can be written to both numbers and variables:

let a = 1; let b = -a; // the contents of a with the opposite sign is written to b alert(b); // shows -1

Or like this:

let a = 1; alert(-a); // shows -1

Create the variable a with the value -100. Display this value on the screen.

Create the variable a, write some positive or negative number to it. Display this value with the opposite sign on the screen.

Plus sign before variables

Just as negative numbers are preceded by the "minus" sign, positive numbers can be preceded by the "plus" sign.

In fact, this plus does nothing, but it is quite valid, see an example:

let a = +1; alert(a); // shows 1
enru