Home >Web Front-end >JS Tutorial >or how to express it in js
How to represent or ||
Overview:
In JavaScript, the "OR" operator | | is used to determine whether a condition is true in a Boolean expression.
Syntax:
<code class="js">boolean1 || boolean2</code>
Function:
|| The operator will return the following value:
Priority:
|| operator has lower priority than && operator and higher than assignment operator.
Example:
<code class="js">// 如果 age 大于 18,则返回 true,否则返回 false const isAdult = age > 18 || false; // 如果 name 是 "John" 或 "Mary",则返回 true,否则返回 false const isJohnOrMary = name === "John" || name === "Mary";</code>
Note:
|| operator can be used for chain comparison, that is:
<code class="js">const isEvenOrOdd = number % 2 === 0 || number % 2 === 1;</code>
Other operators representing or :
There are no other operators in JavaScript that represent the OR operation.
The above is the detailed content of or how to express it in js. For more information, please follow other related articles on the PHP Chinese website!