January 2020
Intermediate to advanced
548 pages
13h 36m
English
The prefix increment and decrement operators allow you to increment or decrement any given value and will evaluate to the newly incremented value:
let n = 0;++n; // => 1 (the newly incremented value)n; // => 1 (the newly incremented value)--n; // => 0 (the newly decremented value)n; // => 0 (the newly decremented value)
++n would technically be equivalent to the following additive assignment:
n += Number(n);
Note how the current value of n is first converted into Number. This is the nature of both the increment and decrement operators: they operate strictly on numbers. So, if n were String, that could not be coerced successfully, then the new incremented or decremented value of n would be NaN:
let n = 'foo';++n; ...
Read now
Unlock full access