Conditions in JavaScript
Operator Usage description
Logical AND (&&) exp1 && exp2 Only if both are TRUE
Logical OR (||) exp1 || exp2 at least one of them is TRUE
Logical NOT (!) !exp is not TRUE
Precendence ex1 && ex2 || ex3 && ex4 AND checked before OR

Ternary Operator

a short way to write a condition

var beverage = (age >= 21) ? "Beer" : "Juice";

var resultHolder = (condition) ? TRUE value : FALSE value;
With multiple conditions:

var resultHolder = (condition) ? value1
                :(condition) ? value2
                :(condition) ? value3
                :value1;
back to main page