Files
30-seconds-of-code/snippets/xor.md
Isabelle Viktoria Maciohsek aa425812b4 Update snippet descriptions
2020-10-22 20:24:44 +03:00

388 B

title, tags
title tags
xor math,logic,beginner

Checks if only one of the arguments is true.

  • 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