title: defining an undefined global variable inside a function
body: <p>This is messy stuff (not my code but I'm stuck to it). A function depends on a globally defined variable.</p>
  
  <pre><code>function variableIssues(){
      alert(someGlobalString);  // alerts "foo"
  }
  </code></pre>
  
  <p>Sometimes this globally defined variable is, <code>undefined</code>. In this case we want to cast it for further processing. The function is modified.</p>
  
  <pre><code>function variableIssues(){
      alert(someGlobalString); // undefined
  
      if (!someGlobalString){
          var someGlobalString = "bar";
      }  
  }
  </code></pre>
  
  <p>However, if this function is now called with a defined someGlobalString, because of javascript evaluation the variable is set to <code>undefined</code> and always get set to <code>bar</code>.</p>
  
  <pre><code>function variableIssues(){
      alert(someGlobalString); // "should be foo, but javascript evaluates a 
                               // variable declaration it becomes undefined"
  
      if (!someGlobalString){
          var someGlobalString = "bar";
      }  
  }
  </code></pre>
  
  <p>I would like to get some suggestions on how to handle <code>undefined</code> global variable. Any ideas?</p>