Files
30-seconds-of-code/snippets/xor.md
Bhaskar Maity e0192d61d3 Update xor.md
2020-10-05 23:54:19 +05:30

21 lines
448 B
Markdown

---
title: xor
tags: math,logic,beginner
---
Returns `true` if only one of the arguments is `true`, `false` otherwise.
- Logical xor using basic or (`||`), and (`&&`), not (`!`) operators.
- 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
```