Before going through this article, we will know about Operator.
What is Operator?
Operator is a special symbol that perform operation on operands. Operands can be values and variables.
|&&||Logical AND||( 5 < 10 && 10 > 8) is true|
|||||Logical OR||( 5 < 10 || 10 < 8) is true|
|!||Logical NOT||!( 5 == 5 ) is false|
Logical AND ( && )
Logical AND operators return true, if both of the operands separated by and ( && ) operator are true, otherwise returns false.
const a = 12, b = 20, c = 12; console.log((a > 5) && (a == c)); // true console.log((a == c) && (a > b)); // false
Logical OR ( || )
Logical OR ( || ) operator returns true if anyone condition separated by OR operator is true. otherwise, return false.
const a = 12, b = 20, c = 12; console.log((a > b) || (a > c)); // false console.log((a == c) || (a > b)); // true
Logical NOT ( ! )
Logical NOT ( ! ) operator evaluate true, if the operand is false and vice-verca.
const a = true, b = false; console.log(!a); // false console.log(!b); // true