How to use OR condition in a JavaScript IF statement?

sadmicrowave picture sadmicrowave · Mar 2, 2010 · Viewed 552k times · Source

I understand that in JavaScript you can write:

if (A && B) { do something }

But how do I implement an OR such as:

if (A OR B) { do something }

Answer

Luca Rocchi picture Luca Rocchi · Mar 2, 2010

Simply use the logical "OR" operator, that is ||.

if (A || B)