Greater than operator given wrong response inside console.log in javascript

前端 未结 2 1253
予麋鹿
予麋鹿 2021-01-27 08:11

I have tried conditional operator inside console.log(). Less than < returns correct response but greater than > returns wrong respon

2条回答
  •  迷失自我
    2021-01-27 08:20

    The lower than and greater than operators are evaluated from left to right (see Operator precedence):

    5 < 6 < 7 = (5 < 6) < 7 = true < 7 = 1 < 7 = true
    
    7 > 6 > 5 = (7 > 6) > 5 = true > 5 = 1 > 5 = false
    

    The boolean values (false/true) are converted to integers (0/1) here. ("If one of the operands is Boolean, the Boolean operand is converted to 1 if it is true and +0 if it is false." (source: MDN))

提交回复
热议问题