Javascript Logical Operators
&& Logical and
|| Logical or
! Logical not
//Logical Binary and Ternary Operators in Javascript
== Equal to
=== Strictly equal to
!= Not equal to
!== Strictly not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
&& Logical and
|| Logical or
! Logical not
? Ternary operator
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
*/
const num = 6;
if (num <= 4 || num <= 8) {
console.log('true')
} else {
console.log('false')
}
//Expected output:true
// logical AND
console.log(true && true); // true
console.log(true && false); // false
// logical OR
console.log(true || false); // true
// logical NOT
console.log(!true); // false
const num = 6;
if (num <= 7 && num <= 8) {
console.log('true')
} else {
console.log('false')
}
//Expected output:true
if (age < 18) text = "Too young to buy alcohol";