Multiple Comparison / Assignment Operators on the Same Line in JavaScript

后端 未结 2 734
清歌不尽
清歌不尽 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:58

    First it's doing the comparison input != 1, and then assigning the result of that (which will be true or false) the variable value. The != is a comparison, the = is an assignment.

    This is exactly the same as any other assignment: The right-hand side is evaluated, and assigned to the left-hand side.

提交回复
热议问题