title: setInterval inside a function produces an error: variable is not defined
body: <p>I do not understand what is wrong. I have three codes:
  <br>First:</p>
  
  <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt;
     var count = 0;
     alert(count);
     var timer = setInterval("count = count + 1; alert(count);",10000);
  &lt;/script&gt;
  </code></pre>
  
  <p><br><br>Second: </p>
  
  <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt;
    function countdown()
    {
     var count = 0;
     alert(count);
     var timer = setInterval("count = count + 1; alert(count);",10000);
    }
    countdown();
  &lt;/script&gt;
  </code></pre>
  
  <p><br><br>Third:</p>
  
  <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt;
     var count = 0;
    function countdown()
    {
     alert(count);
     var timer = setInterval("count = count + 1; alert(count);",10000);
    }
    countdown();
  &lt;/script&gt;
  </code></pre>
  
  <p><br><br> The first code works fine, the second produces an error in the "setInterval" line: "count is not defined", and the third code works fine again. The scope of the "count" variable should be global for the setInterval function in the second code. Why is it not? I am using Mozilla Firefox.
  Thanks.</p>