function test(input){
var value = input != 1;
}
In the above, what is the line inside of the function doing and how does it work?
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.
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.