Operator | Example | Result |
---|
+ | 5 + 2 | 7 |
- | 5 - 2 | 3 |
* | 5 * 2 | 10 |
/ | 5 / 2 | 2.5 |
% | 5 % 2 | 1 |
Operator | Example | Result |
---|
== | 5 == "5" | true (loose equality) |
=== | 5 === "5" | false (strict equality) |
!= | 5 != "5" | false |
!== | 5 !== "5" | true |
> < | 5 > 3 | true |
Logical operators allow you to combine multiple boolean conditions.
Operator | Example | Result | Explanation |
---|
&& | true && false | false | Returns true only if both conditions are true |
` | | ` | `true |
! | !true | false | Inverts the value (NOT) |
if (age >= 18 && hasLicense) {
console.log("You can drive!");
console.log("You cannot drive.");
if (isLoggedIn || isAdmin) {
console.log("Access granted");
console.log("Access denied");
| A | B | A && B
| A || B
|
|-------|-------|----------|----------|
| true | true | true | true |
| true | false | false | true |
| false | true | false | true |
| false | false | false | false |
The !
operator inverts the boolean value: