Creating and assigning console.log a new object
<p>I have seen code like this in several places:</p>

<pre><code>(function() {
    var method;
    var noop = function noop() {};
    var methods = [
        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
        'timeStamp', 'trace', 'warn'
    ];
    var length = methods.length;
    var console = (window.console = window.console || {});

    while (length--) {
        method = methods[length];

        // Only stub undefined methods.
        if (!console[method]) {
            console[method] = noop;
        }
    }
}());
</code></pre>

<p>Specifically I am interested in this line of code </p>

<pre><code>var console = (window.console = window.console || {});
</code></pre>

<p>Why are we creating a new <code>window.console</code> object if <code>window.console</code> is not defined ?</p>

<p>So why are we setting <code>window.console={}</code>?</p>
