Name
|| — NN 2 IE J1 ECMA 1
Synopsis
The OR operator. This operator compares two Boolean expressions for
equality. If either or both expressions evaluate to
true, the result of the || operator also evaluates
to true; if both expressions are
false, the || operator
evaluates to false. A Boolean expression may
consist of a comparison expression (using any of the many comparison
operators) or a variety of other values. See the discussion of the
AND operator for a summary of the most common data types, values, and
their Boolean value equivalent.
You can create compound conditions with the help of the
&& operator. For example, if you want to
see if either or both of two conditions are true, you would create a
condition such as the following:
var userEntry1 = document.forms[0].entry1.value
var userEntry2 = document.forms[0].entry2.value
if (userEntry1 || userEntry2) {
...
}In the compound condition, the || operator wants
to know if either or both operands is true before
it evaluates to true. If the user entered text
into the first field, the condition short-circuits because a
true value of either operand yields a
true result. If text were entered only in the
second field, the second operand is evaluated. Because it evaluates
to true (a nonempty string), the condition
evaluates to true. Only when both operands
evaluate to false does the compound condition
evaluate to false.
Example
if (a <= b || b >= c) {
...
}Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access