I\'m trying to implement XOR in javascript in the following way:
// XOR validation
if ((isEmptyString(firstStr) && !isEmptyString(secondStr)) |
XOR just means "are these two boolean values different?". Therefore:
if (!!isEmptyString(firstStr) != !!isEmptyString(secondStr)) {
// ...
}
The !!
s are just to guarantee that the !=
operator compares two genuine boolean values, since conceivably isEmptyString()
returns something else (like null
for false, or the string itself for true).