how to use logical operators in javascript code example
Example 1: js logical operators
Javascript Logical Operators
&& Logical and
|| Logical or
! Logical not
Example 2: and operator in javascript
var a = true
var b = ""
var c = 1
true && ""
"" && 1
false && 5
Example 3: 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");
}