I stumbled upon this recently and thought it would make a big SO question.
Suppose you assign a string to a local variable and want to change it with a simple condition. This way you insert the inline if line into the line:
var someCondition = true;
var url = "beginning-" + (someCondition)?('middle'):('other_middle') + "-end";
But this does not work properly, the url value will be "in the middle" and not the start-middle. This statement gives the expected result:
var url = "beginning-" + ((someCondition)?('middle'):('other_middle')) + "-end";
The best explanation of why this wins the desired response flag!
source
share