title: Can a function argument shadow a global variable
body: <p>I have a global var defined in a .js file.:</p>
  
  <p>If my function has an argument with the same name as the global variable, the function can not initialise the global variable:</p>
  
  <pre><code>var myvar;
  
  function init(myvar){
      myvar= myvar;
  }
  </code></pre>
  
  <p>But if I change the variable names so the global variable and argument have different names, the function can initialise the global variable: </p>
  
  <pre><code>var myvar2;
  
  function init(myvar){
      myvar2= myvar;
  }
  </code></pre>
  
  <p>(<code>myvar2</code> is then initialised correctly).</p>
  
  <p>Why is this the case ? javascript does not allow two variables with same name in different scope so variable shadowing is occuring ?</p>
  
  <p>I thought the js engine would be be able to distinguish between method scope and global scope in the same way that java does (albeit using the this keyword)</p>