logic operators javascript code example
Example 1: javascript and
var hungry=true;
var slow=true;
var anxious=true;
if(hungry && slow && anxious){
var cause="weed";
}
Example 2: or statment javscript
if (x === 5 || x === 8)
console.log("x is eaqual to 5 OR 8")
Example 3: and operator in javascript
var a = true
var b = ""
var c = 1
true && ""
"" && 1
false && 5
Example 4: and operator in javascript
console.log(5 & 13);
Example 5: 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");
}