HTML and CSS Reference
You've gained some familiarity with variables, but you
should know about a few more operators. These operators
don't have any analogue in arithmetic; they're only useful
when you have values stored in a variable.
Special operators for variables
Two operators that won't be familiar to you
from school arithmetic are the post-
increment ( ++ ) and post-decrement ( -- ) opera-
tors. They increase and decrease, respec-
tively, the value of a number by one. Post
means they perform the change after the
value has been used in an expression.
Study the sequence of operations in this
screenshot. Notice that the values assigned
to a and b are those of i before the incre-
ment or decrement.
You also need to know about the += opera-
tor and its relatives.
The need to store the result of an expres-
sion into a variable when it's one of the
operands is so common that a shortcut is
a = a + b;
you can write
a += b;
This works for the other arithmetic opera-
tors, as you can see in the screenshot.