title: setting a javascript variable with an if statement -- should the 'var = x' be inside or outside the IF?
body: <p>This may be a basic question but I'm having difficulty finding an answer.</p>
  
  <p>You want to set var B based on var A</p>
  
  <p>would you do</p>
  
  <pre><code>var B = if(A == "red"){"hot"}else{"cool"}
  </code></pre>
  
  <p>I don't think this works.</p>
  
  <p>I guess you could do</p>
  
  <pre><code>if(A == "red"){var B = "hot"}else{var B = "cool"}
  </code></pre>
  
  <p>This doesn't seem particularly elegant. I mean I would prefer something that starts with var b = .... just for clarity's sake.</p>