title: How does scope work in this Javascript code?
body: <p>I'm reading a Javascript (ES6) book, and in Chapter 7 (Scope) there's an obscure example (at least for me as a beginner) that I can't wrap my head around.</p>
  
  <pre><code>const f = (function() {
              let count = 0;
              return function() {
                  return `I have been called ${++count} time(s).`;
                  }
              })();
  
  f(); // "I have been called 1 time(s)."
  f(); // "I have been called 2 time(s)."
  //...
  </code></pre>
  
  <p>So, the count variable is initialized at 0 but, why is the value of it still "alive" in subsequent calls to the f function? is the first unnamed function still valid behind the scenes somewhere in memory or anything like it?</p>