Chain equality operator in javascript

Viewed 465

I have a question about how chain equality works in JavaScript.

For example in python if you have: a, b = 1, 2
a == b == False //False
Because it converts to: (a == b) and (b == False) So, finally it is False.

But when I try this in js: console.log(1==2==false) // true

I got "true". I don't know why and how it is worked in js. could you please help me out?

2 Answers

Reading left to right:

1==2 is false

false==false is true

in the code 1 == 2 == false

we read it as 1 == 2 == false

so basically 1 == 2 is false

and fasle == false is true

Related