Why is 1===1===1 false?

前端 未结 5 2134
我寻月下人不归
我寻月下人不归 2021-01-01 09:37

In a browser console, entering 1===1 evaluates to true. Entering 1===1===1 evaluates to false.

I assume that this

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 10:06

    Correct behaviour. Since

    1===1 // value is true
    

    but

    true===1 // it's false
    

    There are two reasons for this:

    1. true is a boolean type where 1 is integer
    2. simply, 1 is not equal to true.

    so

    1===1===1 // false
    

提交回复
热议问题