I was just doing the ‘rock, paper, scissors’ exercise on the full stack course, and had a thought while inputing some parameters into an if statement. The answer to this particular exercise is to use the || or logical operator and to ask for one of three options. Could the same result be returned with either of the two codebytes below:
The second one doesn’t work because when you write:
if (condition == "something" || "somethingelse")
You’re actually checking if a) condition == "something" and (importantly) b) whether “somethingelse” is true. Since any non-empty string is a truthy value, the second part of the condition will always return true, and so the entire condition will always evaluate as true, and whatever’s in the if block will run.
A similar thing (in terms of outcome) happens with the first codebyte as well.
EDIT (I had to research the comma): As it turns out, the comma (,) is an actual operator in JavaScript; an operator which evaluates the whole expression, and returns the last one. So, in your case, the if statement essentially becomes:
if ("scissors")
Because "scissors" is the last ‘expression’ in the list, and, since that is a truthy value, the if statement will always evaluate to true.