When is this scope/closure being garbage collected in javaScript?
<p>I am doing a course which is going through scope/closures and briefly mentions garbage collection. During the course a question is posed:</p>

<blockquote>
  <p>How long does the scope stay around? And the answer was—until
  there's no longer any references to it. Yep, so what we basically said
  was, a closure is kind of like a reference to a hidden scope object.
  So as long as there's some function that still has a closure over the
  scope, that scope's going to stay around. But as soon as that closure
  goes away, scope can get garbage collected. "</p>
</blockquote>

<pre><code>var sum = function sumHndlr(x, y) {
    if (y !== undefined) {
        return x + y;
    } else {
        return function(y) {
            return x + y;
        }
    }
}
</code></pre>

<p>So to me, the reference to the closure is when we assigned the function to the <code>sum</code> variable, but won't that mean it lasts forever or am I not understanding the way the js will execute in regards to the compiler parser etc.?</p>