HTML and CSS Reference
In-Depth Information
EXPLANATION
(
CONTINUED
)
2
If the value of
answer
is any one of
McDonald's
or
Taco Bell
or
Wendy's
, the state-
ment enclosed within the curly braces is executed: An alert box appears display-
ing
No fast food today, thanks
. (See Figure 5.14.) If the user enters any other value,
nothing happens.
Figure 5.13
The user enters a value.
Figure 5.14
If the user enters any one of the values in line 2, this alert box appears.
The
!
Operator (Logical NOT).
In the English statement “That's
not
true!” the
word
not
is used for negation: Not true is false, and not false is true. JavaScript provides
the NOT (
!
) operator for negation. The
!
operator is called a unary operator because it
has only one operand; for example,
! true
or
! 5
. It returns
true
if the expression evaluates
to false and returns
false
if the expression evaluates to true. See Table 5.14.
Table 5.14
Logical NOT Examples
Expression
What It Evaluates To
! "this"
false
! 0
true
! 2
false
! false
true
! null
true
! undefined
true