title: is this function a closure in javascript?
body: <pre><code>    function f1(){
          var n=999;
          function f2(){
              alert(n); // 999
          }
      }
  </code></pre>
  
  <p>is the function <code>f2()</code> a closure? if not? why?</p>
  
  <p>but in this post. <a href="https://stackoverflow.com/questions/111102/how-do-javascript-closures-work">How do JavaScript closures work?</a>
  why it says:</p>
  
  <pre><code>function foo(x) {
    var tmp = 3;
    function bar(y) {
      alert(x + y + (++tmp));
    }
    bar(10);
  }
  foo(2)
  </code></pre>
  
  <p><strong>That is not a closure.A closure is when you return the inner function. The inner function will close-over the variables of foo before leaving.</strong> why?</p>
  
  <p>but i don't know what's the difference between the example i made and another i cited, one is not a closure.but one is. i think the two example is the same. </p>