Files
30-seconds-of-code/snippets/xor.md
Angelos Chalaris 7261062778 Update xor.md
2020-10-06 19:09:30 +03:00

415 B

title, tags
title tags
xor math,logic,beginner

Returns true if only one of the arguments is true, false otherwise.

  • Use the logical or (||), and (&&) and not (!) operators on the two given values to create the logical xor.
const xor = (a, b) => (( a || b ) && !( a && b ));
xor(true, true); // false
xor(true, false); // true
xor(false, true); // true
xor(false, false); // false