Why in this case
if (! x === y) {
console.log ('true');
} else {
console.log ('false');
}
gets false since the negation operator is used. Without the negation operator it also gets false because the operator ‘===’ checks if it compares the same values with the same data type. Why, then, after putting the exclamation point directly after x, does he still get false, since it contradicts falsehood, so I should get the truth?
!x
negatesx
, then compares that toy
. Assumingx
is truthy,!x
isfalse
. So unlessy
is exactlyfalse
,!x === y
isfalse
. Read as: negated x equals y.x === y
is probably alsofalse
because the two values aren’t equal.x !== y
is the negated comparison operator, meaning "is not equal". So wherex === y
isfalse
,x !== y
istrue
.x !== y
is equivalent to!(x === y)
, negating the entire result, not justx
.