Multiple comparison operators in a JavaScript boolean expression

后端 未结 3 794
不思量自难忘°
不思量自难忘° 2020-12-11 07:34

I\'m trying to check whether the variable y is less than x and greater than z, but this boolean expression is returning false for some reason. Does JavaScript allow boolean

3条回答
  •  清歌不尽
    2020-12-11 07:39

    Change your test to

    if (x > y && y > z){
    

    When you write (x > y > z), this is equivalent to ((x>y)>z), so you're comparing a boolean (x>y) to z. In this test, true is converted to 1, which isn't greater than 2.

提交回复
热议问题