In JavaScript, is it possible to place a Conditional statement after an Or operator? If so, why is the following fails for me?
var value = 1 || true ? 2 : 3; // equals to 2
When I set value to be equals to [1 || true ? 2 : 3], I get an unexpected result.
The result that get is that:
value == 2
I've expected value to be equals to 1 (value= = 1), since 1 is truthy, and the Or statement should have return 1. The conditional statement is not even supposed to be executed.
The only way val can be equals to 2 (val == 2) is if the Or operator is behaving not as expected, and runs the second part of the Or statement and the Conditional statement that is in it.
Why is it behaving that way?
(1 || true) ? 2 : 3