JavaScript piece of code explanation
<p>Check out this piece of JavaScript code:</p>

<pre><code>(function (w, d) {
    var loader = function () {
        var s = d.createElement("script"), tag = d.getElementsByTagName("script")[0];
        s.src = "https://example.org/script.js";
        tag.parentNode.insertBefore(s,tag);
    };
    w.addEventListener ? w.addEventListener("load", loader, false) :
                         w.attachEvent("onload", loader);
}) (window, document);
</code></pre>

<p>Why did the author of this code use this method to include a script in the document?
And what is the usefulness of the line:</p>

<pre><code>w.addEventListener ? w.addEventListener("load", loader, false) :
                     w.attachEvent("onload", loader);
</code></pre>

<p>Last point: I'm a JavaScript beginner, what is the <code>(window, document)</code> at the end?</p>
