title: What happens when JavaScript variable name and function name is the same?
body: <p>I have the following code, where I declare a function and after it, a variable with the same name as the function:</p>
  
  <pre><code>function a(x) {
      return x * 2;
  }
  
  var a;
  alert(a);
  </code></pre>
  
  <p>I expected this to alert <code>undefined</code>, but if I run it, the alert will display the following:</p>
  
  <blockquote>
    <p>function a(x) {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;return x * 2<br>
    }</p>
  </blockquote>
  
  <p>If I assign  a value to the variable (like <code>var a = 4</code>), the alert will display that value (<code>4</code>), but without this change <code>a</code> will be recognized as a function.</p>
  
  <p>Why is this happening?</p>