Section 1: Overview
The logical operators are && (And), || (Or), and ! (Not).
- The && requires that all conditions are true in order for the result to be true.
-
The || requires that
any condition is true in order
for the result to be true.
- Conversely, || requires that all conditions are false in order for the result to be false.
-
The ! operator negates (reverses or cancels) any condition.
- So true becomes false and vice versa.
- Assume in the truth tables below that p and q are conditions that can assume the values true or false.

Section 2: Proper Procedure
&& and || can only be used to test a complete condition.
if (( testCondition == 1 ) || ( testCondition == 2 ) || ( testCondition == 4 ))
The following is an invalid statement:
if (testCondition == 1 || 2 || 4)
The same holds true for the &&. The following is invalid:
if ( grade < 90 && >= 80 )
Similarly, you cannot write a statement like
if ( 90 < grade <= 80 )
The correct syntax for such a statement is
if (( grade < 90 ) && ( grade >= 80 ))
Section 3: Short-Circuit Evaluation
As logical expressions are evaluated left to right, they are tested for possible "short-circuit" evaluation using the following rules:
- false && anything is short-circuit evaluated to false
- true || anything is short-circuit evaluated to true
The rules of logic guarantee that these evaluations are always correct.

Section 4: Precedence of JavaScript Logical Operators

Section 5: Precedence of JavaScript Operators
A complete table of operator precedence can be found here.
