Logical operators in JS
Logical operators are used to combine two or more Boolean values (true/false) to generate a new Boolean value. In JavaScript, there are the following three logical operators:
1. And (&&)
Example:
<code class="js">const isLoggedIn = true; const hasAccess = true; const canAccess = isLoggedIn && hasAccess; // true</code>
2. Or (||)
Example:
<code class="js">const isMember = false; const isFriend = true; const canJoin = isMember || isFriend; // true</code>
3. Not(!)
Example:
<code class="js">const isNight = false; const isDay = !isNight; // true</code>
Usage scenarios
Logical operators in JavaScript Widely used in:The above is the detailed content of what are logical operators in js. For more information, please follow other related articles on the PHP Chinese website!