Logical or Boolean Operators Flashcards
Logical operators
Logical operators are sometimes called Boolean operators because they are typically used with Boolean
values, which are either true or false. The logical operators are: AND, OR, and NOT.
if two variables needs to be both true
AND
The AND operator returns true if both operands are true, but false if one or both of the operands are false.
In JavaScript, the AND operator is indicated with two ampersands (&&).
if (num1 == 0 && num2 == 0) {…}
if only one needs to be true,
OR
The OR operator returns true if either or both operands are true, but false if both operands are false. In
JavaScript, the OR operator is indicated with two vertical bars or pipes (||).
if (num1 == 0 || num2 == 0) {…}
If you want something to not do that thing
NOT
The NOT operator returns true if its single operand is false, and false if its single operand is true. In
JavaScript, the NOT operator is indicated with an exclamation point (!).
var gameover = false;
if (!gameover) {…}