xor

x xor y

xor(x, y)

Try it yourself:

See also:

Test exclusive alternatives with xor

xor(a, b) returns true when exactly one of its Boolean inputs is true. It returns false when both inputs agree: both true or both false. Exclusive OR is useful for validations where one—and only one—option must be selected.

Reading an xor condition

For example, a form may allow either a delivery address or a pickup location, but not both. Xor expresses that rule directly. Compare or, which allows one or both conditions, and and, which requires both. Use not to invert a condition before combining it.

Logical and bitwise use

This function is for logical conditions. For integer bit patterns, use bitXor, which applies the same exclusive-or idea to each binary digit. Keep these operations separate: a truth test is not automatically a request to manipulate integer bits.

Input caveats

Make Boolean intent explicit, particularly when input values may be empty strings, zero, or missing. Parenthesize compound expressions so the intended evaluation order is clear. If the requirement is “values differ” rather than “exactly one condition holds,” unequal may better describe the comparison.

All functions