title: JavaScript local and global variable confusion
body: <p>I am new to JavaScript and I was doing some practices on local and global variable scopes. Following is my code(<a href="http://jsfiddle.net/xjmBf/1/" rel="noreferrer">fiddle</a>):</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var myname = "initial"
  function c(){
      alert(myname);
      var myname = "changed";
      alert(myname);
  }
  c();</code></pre>
  </div>
  </div>
  </p>
  <p>When the first alert is called, it is showing <code>myname</code> as undefined. So my confusion is why I am not able to access a global instance of <code>myname</code> and if I don't define <code>myname</code> within the function then it will work fine.</p>