HTML and CSS Reference
In-Depth Information
out the current value of whatever
variable you put in the brackets.
Unlike in algebra, you have to define
all the variables that appear on the
right side of the equals sign before
you use them. The sequence of oper-
ations here shows what happens if
you don't.
When JavaScript can't understand
your code or is unable to execute it,
an error occurs. Usually this immedi-
ately stops the execution of whatever
program is running. You can see in
this example that the error that c
isn't defined wasn't discovered until
b was defined, because the initial
error stopped execution.
After you create a variable, you can
assign it a new value at any time.
When you use the variable in a cal-
culation that assigns a new value to
itself, remember that the assignment
operator sets the new value, and that
always happens last—the value isn't
updated until the end of the
If you put a number in a variable,
nothing stops you from adding a
string to it. But as with previous situ-
ations where JavaScript is equally
happy with a string or a number, this
can lead to confusing errors.
Search WWH ::

Custom Search