0

console.log(`${window === this} (window === this)`)
console.log(`${window === self} (window === self)`)
console.log(`${this === self} (this === self)`)

console.log(`${window === this === self} (window === this === self)`)

Why is window === self === this false in JavaScript

Nice18
  • 476
  • 2
  • 12
  • 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
  • 30,714
  • 6
  • 20
  • 43
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
  • 6,480
  • 2
  • 27
  • 54