javascript Operators ||
|| | Firefox/Netscape/NN 2 IE 3 ECMA 1 |
|
|
The OR 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:
|
|
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) { ... } |
Powered by Linode.