Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Determining Truth With Logical Operators

Remember also that logical operators have a 
precedence just like the arithmetic operators. 
! has the highest precedence, followed by && and then ||. 
If you need to override the precedence, you can wrap whatever you 
want to execute first in parentheses in order to give it priority. 
Parentheses are always executed first. Here are some examples 
demonstrating how you can control the order of operations:

let a = true;
let b = true;
let c = false;
let d = false;

a && b && c && d         // Operators are executed left to right
a || b && c || d         // b && c is evaluated first
(a || b) && (c || d)     // a || b is evaluated, then c || d, then the &&
!(a || b) && (c || d)    // same as above, but (a || b) is negated before the && is evaluated
 
PREVIOUS NEXT
Tagged: #Determining #Truth #With #Logical #Operators
ADD COMMENT
Topic
Name
2+1 =