tags:

views:

99

answers:

4
+1  Q: 

Javascript syntax

How do you say if (A == 0) OR (B == 0)?

+9  A: 
if (  A == 0  ||  B == 0 ) {
}
Kieveli
I wish I could accept multiple answers.
cf_PhillipSenn
I've faced this dilemma before; what I did was give the best answer a checkmark (15pts) and the rest of them that were almost as good +1s.
Jason S
I always give it to the guy with less points =)
Kieveli
+10  A: 
if (A == 0 || B == 0)

or

if ((A == 0) || (B == 0))

Check out Control Structures and Operators on Wikibooks

Boris Guéry
+14  A: 

Just to be snarky:

if (A === 0 || B === 0)
Joel Coehoorn
Now all you have to do is change your name from "Coehoorn" to "Coercion" ;)
Eoin Campbell
Nosredna
+6  A: 

depends if you mean exclusive or inclusive OR :)

Inclusive OR:

if(A == 0 || B == 0) 
{ 
}

Exclusive OR:

if(A == 0 && B != 0 || A != 0 && B == 0) 
{ 
}
Brian R. Bondy
Actually a simpler xor can be achieved by if(!A != !B) but perhaps readability suffers. JS also has a native bitwise xor in ^ where that applies.
annakata
annakata: Why not (A != B). It will give the same truth table as (A==0 XOR B==0).
Daniel W