Primer on Logical Operators

Javascript uses three logical operators: && (AND), || (OR), and ! (NOT). The first two take two boolean values and combine them, while the third takes a single boolean value and alters it. For example, if P and Q are the names of two boolean variables, then one could form P && Q (pronounced "P AND Q"), P || Q (pronounced "P OR Q"), and ! P (pronounced "NOT P").

The value of a boolean relation depends upon the values of the components. You can think of the expressions as asking a question. For example, P && Q asks, "Are P and Q (both) true?". P || Q asks, "Is (either) P or Q true?" Finally, ! P asks,"Is P not true?"

The tables below give the values for the each operator given possible values for P and Q. (These are called "truth tables".)

P && Q
  P true P false
Q true true false
Q false false false

P || Q
  P true P false
Q true true true
Q false true false

! P
P true P false
false true