function test(input){
var value = input != 1;
}
In the above, what is the line inside of the function doing and how does it work?
javascript
function test(input){
var value = input != 1;
}
In the above, what is the line inside of the function doing and how does it work?
Best Answer
First it's doing the comparison
input != 1
, and then assigning the result of that (which will betrue
orfalse
) the variablevalue
. 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.