HTML and CSS Reference
In-Depth Information
Table 5.13 Logical OR Examples (continued)
Expression
What It Evaluates To
"honest" || true
honest
true || ""
true
true || "honest"
true
5 || 0
5
5 || -6
5
5 || false
5
null || 0
0
null || ""
(empty string)
null || false
false
"hello" || true || 50
hello
"this" || "that"
this
EXAMPLE 5.9
<html>
<head>
<title>Logical OR Operator</title>
</head>
<body bgcolor="lightblue">
<big>
<script type="text/javascript">
1
var answer = prompt("Where should we eat? ", "");
2
if ( answer == "McDonald's" || answer == "Taco Bell" ||
answer == "Wendy's"){
3
alert("No fast food today, thanks.");
}
</script>
</big>
</body>
</html>
EXPLANATION
1
The user is prompted to choose a place to eat. The variable called answer is as-
signed the value he or she enters. (See Figure 5.13.)
Search WWH ::




Custom Search