Multiple Comparison / Assignment Operators on the Same Line in JavaScript

后端 未结 2 735
清歌不尽
清歌不尽 2021-01-17 04:14
function test(input){
   var value = input != 1;
}

In the above, what is the line inside of the function doing and how does it work?

2条回答
  •  野的像风
    2021-01-17 04:54

    See Operator Precedence.

    != has a precedence of 9 and = has a precedence of 17.

    Therefore it evaluates input != 1 and then assigns the result to value.

提交回复
热议问题