or js operator code example
Example 1: javascript and operator
//AND Operator expressed as &&
const x = 7;
const y = 4;
(x == 7 && y == 5); // false
(x == 3 && y == 4); // false
(x == 7 && y == 4); // true
if (condition == value && condition == otherValue) {
return something;
}
Example 2: or operator javascript
//|| is the or operator in JavaScript
if(a == 1 || b != 'value'){
yourFunction();
}
Example 3: 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");}
/* Output:
TRUE
FALSE
TRUE
*/
Example 4: and operator in javascript
//&& returns true if both values are true
//or returns the second argument if the first is true
var a = true
var b = ""
var c = 1
true && "" //""
"" && 1 //""
false && 5 //false
Example 5: or operator js
//OR Operator
const x = 7;
const y = 4;
(x == 5 || y == 5); // false
(x == 7 || y == 0); // true
(x == 0 || y == 4); // true
(x == 7 || y == 4); // true
Example 6: js or operator
/*OR operator:*/
||
// example:
var a = 10;
var b = 5;
if(a > 7 or b > 7){
print("This will print!")
}
// Even though a is not less than 7, b is, so the program will print
// the statement.