title: javascript global variable undefined inside function sometime
body: <p>For some reason a JavaScript global variable becomes undefined inside function when set to local variable sometime. 
  For example, in below sample the <code>local</code> often become "<code>undefined</code>".
  Could anyone of you please advise?</p>
  
  <p>I'm expecting the value of "<code>local</code>" is "global value" in <code>functionB()</code> and <code>functionC()</code> or <code>doStringProcessingA()</code> and <code>doStringProcessingB()</code>. The value of "<code>local</code>" is "<code>undefined</code>". I'm sure there's no other places assign value or set undefined to global in anywhere.</p>
  
  <p>I've checked below links, but it seems not related.
  <a href="https://stackoverflow.com/questions/29667199/hoisted-javascript-variables">&#39;Hoisted&#39; JavaScript Variables</a>
  and
  <a href="https://stackoverflow.com/questions/30469755/why-a-variable-defined-global-is-undefined">Why a variable defined global is undefined?</a></p>
  
  <p>functionA() was called by onClick event from HTML.</p>
  
  <pre><code> var global;
  
   function functionA(){
      global = "global value";
   }
  
   function functionB(){
      var local = global;     
      doStringProcessingA(local);
   }
  
   function functionC(){
      var local = global;     
      doStringProcessingB(local);
   }
  
  &lt;div onclick="functionA()"&gt;
      &lt;span class="Text"&gt;Submit&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>