0

// These are true

console.log(window === this)
console.log(window === self)
console.log(this === self)

console.log(window === this === self) // Why is this false?

window is equal to this,
window is equal to self, and
this is equal to self

So, why is window === self === this false in JavaScript

Nice18
  • 388
  • 1
  • 9
  • 2
    because `a === b === c` is equivalent to `(a === b) === c`, thus `true === c` which is obviously wrong if `c` is not boolean – derpirscher Nov 21 '21 at 16:12

2 Answers2

1

Because true is not equal to this.

This expression:

window === self === this

Is equivalent to:

true === this

Which is false, because this is not a boolean.

Spectric
  • 27,594
  • 6
  • 14
  • 39
0

Because you can't chain equality operators in such a way in javascript. window === this === self is actually the same as: (window === this) === self where the parentheses is evaluated first. In other words window === this === self equals true === self which evaluates to false.

Olian04
  • 5,841
  • 2
  • 29
  • 49