I'm new to js and I wonder if there is a XNOR operator in JS. I tried !(a^b)
but it gives weird result. For example:
var a,b="aa";
a^b
this code returns true, however, I XNOR returns false.
UPDATE
I need to return true if the two operand are true(different from false values), or the two are false (both equals to : null, undefined,""-empty string- or 0)
Above is the truth table for XNOR. If A and B are both FALSE or TRUE, the resulting XNOR is true. Therefore, it seems to me as if simply checking for equality is actually the equivalent of XNOR.
So:
(a === b) = (a XNOR b)
EDIT: If you need to convert to boolean first, use
!a === !b
Boolean negation produces booleans, and the fact that it also negates is fine here. (If we needed to avoid negating, !!
would do the job.)