logical or operator javascript code example
Example 1: or operator javascript
//|| is the or operator in JavaScript
if(a == 1 || b != 'value'){
yourFunction();
}
Example 2: logical operators javascript
// There are 3 Javascript Logical Operators
// || (OR)
// && (AND)
// ! (NOT)
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");
}