0

Suppose I have two boolean variables and want to know when they are both true or false, in other words, I need a logical equality operator.'

Every JS book suggests bitwise operators, and XOR operator does pretty much the same thing but inverted: it indicates whether boolean variables have different value. So I come up with an expression:

const a = true
const b = false
const c = !(a ^ b)

This code seems quite not obvious when reading. Is there a better and more obvious solution?

pttsky
  • 737
  • 5
  • 15

1 Answers1

3
  const c = a === b

Just compare them.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151