From 34e5528132f8aa769ae409fd0887e065805c05ee Mon Sep 17 00:00:00 2001 From: Bhaskar Maity Date: Mon, 5 Oct 2020 23:49:21 +0530 Subject: [PATCH] xor.md Added --- snippets/xor.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 snippets/xor.md diff --git a/snippets/xor.md b/snippets/xor.md new file mode 100644 index 000000000..51fe2fcc0 --- /dev/null +++ b/snippets/xor.md @@ -0,0 +1,20 @@ +--- +title: xor +tags: math,logic,beginner +--- + +Returns `true` if only one of the arguments is `true`, `false` otherwise. + +- Using basic or (`||`), and (`&&`), and not (`!`) operators Logical xor. +- You can use the Bitwise xor (`^`) operator also on the two given values. + +```js +const xor = (a, b) => ( ( a || b ) && !( a && b ) ); +``` + +```js +xor(true, true); // false +xor(true, false); // true +xor(false, true); // true +xor(false, false); // false +``` \ No newline at end of file