HTML and CSS Reference
In-Depth Information
In the first example, the multiplica-
tion is performed before the addi-
tion, so the result is 8. The
terminology is that multiplication
has a higher precedence than addition.
To explicitly control the order of
evaluation, you can use parentheses
to group operations. The second
example shows a forced left-to-right
evaluation.
In addition to adding numbers, the +
operator can add text together. Text
values in a JavaScript program are
referred to as strings . Strings are
always demarcated by either double
or single quotes—it doesn't matter
which as long they're used in pairs,
as the first two examples show.
Strings and numbers can be added
to each other in certain circum-
stances, although using any of the
other arithmetic operators with
strings leads to a not-a-number
(NaN) result.
If the string is also a number, it can be used with normal arithmetic
operations, but the results won't always be what you expect. Java-
Script makes up its own mind about whether you mean arithmetic or
string addition.
In the first two examples, string addition is
used rather than numeric, because addition
 
Search WWH ::




Custom Search