title: Why does this JavaScript code print "undefined" on the console?
body: <p>I have the following JavaScript code:</p>
  <pre><code>var counter = 0;
  function printCounter(){
     console.log(&quot;counter=&quot; + ++counter);
     setTimeout(printCounter, 1000);
  }
  printCounter();
  </code></pre>
  <p>I expect that it should print this output:</p>
  <pre><code>counter=1
  counter=2
  counter=3
  ...
  </code></pre>
  <p>But instead it prints following:</p>
  <pre><code>counter=1
  undefined  // &lt;-- Notice this &quot;undefined&quot;
  counter=2
  counter=3
  ...
  </code></pre>
  <p>Why does it print &quot;undefined&quot; after the first iteration?</p>
  <p>Important: I see such behavior <em>only</em> when the code executed in the JavaScript console. If it's the part of a page, it works fine.</p>