I came across this recently and thought it would make a great SO question.
Suppose you are assigning a string to a local variable and you want to vary it by a simple condition. So you insert an inline if statement into the string:
var someCondition = true;
var url = "beginning-" + (someCondition)?('middle'):('other_middle') + "-end";
But this doesn’t work as expected, the value of url will be “middle”, not beginning-middle-end. This statement yields the expected result:
var url = "beginning-" + ((someCondition)?('middle'):('other_middle')) + "-end";
Best explanation of why this is wins the coveted answer flag!
It is of course to do with precedence.
is interpreted as: