How do I validate favicons using Javascript?
<p>In a previous post on <a href="http://stackoverflow.com/questions/7034333/adding-favicons-with-generic-option">SO</a> I asked how to display favicons with a generic option for favicons that do not exist.  </p>

<pre><code>&lt;img src="example.com/favicon.ico"; alt=""/&gt;
</code></pre>

<p>This code was posted:</p>

<pre><code>var img = document.getElementsByTagName('img')[0],
    favicon = new Image;

favicon.src = 'http://example.com/favicon.ico'

favicon.onerror = function() 
  {
  img.src = 'http://url-on-local-server.com/favicon.ico';
  }
</code></pre>

<p>However I do not understand the need for "new Image", why can't I just use the existing image like this?</p>

<pre><code>var img = document.getElementsByTagName('img')[0],
img.src = 'http://example.com/favicon.ico'
img.onerror = function() 
  {
  img.src = 'http://url-on-local-server.com/favicon.ico';
  }
</code></pre>
