1. Logical AND (&&
)
The AND (&&
) operator returns true
only if both operands are true
. Otherwise, it returns false
.
Expression | Result |
---|---|
true && true | true |
true && false | false |
false && true | false |
false && false | false |
Example
2. Logical OR (||
)
The OR (||
) operator returns true
if at least one operand is true
. It returns false
only if both are false.
Expression | Result |
---|---|
true || true | true |
true || false | true |
false || true | true |
false || false | false |
3. Logical NOT (!
)
The NOT (!
) operator reverses a Boolean value:
!true
→false
!false
→true
4. Logical XOR (^
) (Exclusive OR)
The XOR (^
) operator returns true
only if the operands are different.
It returns false
if both are the same.
Expression | Result |
---|---|
true ^ true | false |
true ^ false | true |
false ^ true | true |
false ^ false | false |