title: One function changing another function's local variable?
body: <p>I had a problem with some JavaScript functions that had me scratching my head for about an hour until some well-placed alert()'s revealed something which surprised me. One function was changing another function's local variables, it seems. I wrote a simple test script:</p>
  
  <pre><code>function first() {
      msg = "1111";
  
      second();
  
      alert(msg);
      }
  
  
  function second() {
      msg = "2222";
      }
  </code></pre>
  
  <p>When I call first() I'd expect to get an alert box saying "1111" but I get "2222" instead. How is it that second() is affecting a local variable belonging to first()? Am I missing something or is this a bug?</p>
  
  <p>I'm using Firefox 12.0.</p>