Question regarding execution of JS code
<p>I just encountered with this code:</p>

<pre><code>foo = (function() {
    var div = document.createElement('div');
    return function(html) {
        div.innerHTML = html;
        var item = div.firstChild;
        div.removeChild(item);
        return item;
    };
})();
</code></pre>

<p>and it is being used like this:</p>

<pre><code>var element=foo('&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;table&gt;');
</code></pre>

<p>I noticed that the above return the JavaScript element with it. I wonder can't it be done only with this -</p>

<pre><code>var element=$('&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;table&gt;')[0];
</code></pre>

<p>What exactly the original JS function is doing actually? What is the benefit of taking this <em>var div = document.createElement('div');</em> outside the return statement ?</p>
