title: JavaScript Syntax: Inline Ifs in String Assignment Statements
body: <p>I came across this recently and thought it would make a great SO question. </p>
  
  <p>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:</p>
  
  <pre><code>var someCondition = true;
  var url = "beginning-" + (someCondition)?('middle'):('other_middle') + "-end";
  </code></pre>
  
  <p>But this doesn't work as expected, the value of url will be "middle", not beginning-middle-end. This statement yields the expected result:</p>
  
  <pre><code>var url = "beginning-" + ((someCondition)?('middle'):('other_middle')) + "-end";
  </code></pre>
  
  <p>Best explanation of why this is wins the coveted answer flag!</p>