How to use OR condition in a JavaScript IF statement?
Simply use the logical "OR" operator, that is ||
.
if (A || B)
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) ) { ... }
if (A || B) { do something }