title: JavaScript closures and memory management
body: <p>I'm curious as to how memory is handled with variables inside closures. Take this code for example -</p>
  
  <pre><code>function iAmAClosure() {
      var txtName = document.getElementById('name');
  
      function validation() {
          if (txtName.value.length === 0) {
              return false;
          }
          return true;
      }
  
      document.getElementById('submit').onclick = function () {
          return validation();
      }
  }
  </code></pre>
  
  <p>My <code>validation</code> function is called whenever the user clicks on a button. </p>
  
  <p>My question is, does the <code>txtName</code> variable stay in memory as long as the page is active, or is it GC'ed and initialized every time the method validation is called? Is there something more to it then that?</p>
  
  <p>What's better performance wise?</p>