logical operators javascript code example
Example 1: js logical operators
Javascript Logical Operators
&& Logical and
|| Logical or
! Logical not
Example 2: or operator in javascript
var a = true;
var b = false;
if(a || b) {
}
Example 3: javascript and
var hungry=true;
var slow=true;
var anxious=true;
if(hungry && slow && anxious){
var cause="weed";
}
Example 4: or operator javascript
if(a == 1 || b != 'value'){
yourFunction();
}
Example 5: or operator javascript
var a = 2;
var b = 5;
var c = 10;
if (a === 3 || a === 2) {
console.log("TRUE");
} else {console.log("FALSE");}
if (a === 4 || b === 3 || c === 11) {
console.log("TRUE");
} else {console.log("FALSE");}
if (b === 5 || c != 10) {
console.log("TRUE");
} else {console.log("FALSE");}
Example 6: logical operators javascript
if (a || b) {
console.log("I will run if either a or b are true");
}
if (a && b) {
console.log("I will run, if and only if a and b are both true");
}
if (!a) {
console.log("I will only run if a is false");
}
if (a) {
console.log("I will only run if a is true");
}