How to use OR condition in a JavaScript IF statement?
Solution 1:
Simply use the logical "OR" operator, that is ||
.
if (A || B)
Solution 2:
Worth noting that ||
will also return true
if BOTH A
and B
are true
.
In JavaScript, if you're looking for A
or B
, but not both, you'll need to do something similar to:
if( (A && !B) || (B && !A) ) { ... }
Solution 3:
Use the ||
operator.
Solution 4:
if (A || B) { do something }
Solution 5:
||
is the or operator.
if(A || B){ do something }