HTML and CSS Reference
In-Depth Information
can be performed on both numbers and
strings and one of the operands is a string.
The multiplication operation can only be
used with numbers, so the strings are con-
verted automatically to numbers.
The automatic conversion of numbers to strings can lead to some
unexpected and unwanted behavior, or
bugs
in programmer parlance, in
your JavaScript programs. in the section “Branching and looping.''
you'll learn how to force your operand to be a number.
Comparisons
Comparisons
are operators that produce a
true
or
false
value, otherwise
known as a
Boolean
value. Comparison operators are crucial when it
comes to branching and looping (see “Branching and looping”). There
are general-purpose comparison operators as well as several operators
that are intended for Boolean values. The three main Boolean opera-
tors are as follows:
&&
AND
Returns
true
if both oper-
ands are true
Returns
true
if either oper-
and is true
||
OR
Returns
true
if its operand
is false
!
NOT
Experiment with these operators in the
console until you're comfortable with these
meanings.