title: What is the difference between a closure and a module?
body: <p>I know that a module like this one:</p>
  
  <pre><code>function User(){
      var username, password;
  
      function doLogin(user, pw){
          username = user;
          password = pw;
      };
      var publicAPI = {
          login: doLogin
      };
      return publicAPI;
  }
  </code></pre>
  
  <p>has a closure inside of it: <code>doLogin</code>, and is remembering the values of the variables <code>username</code> and <code>password</code> that are inside <code>User</code>, what makes this a "closure". What I don't quite understand is if whenever we use a closure we are using the module pattern? or as soon as I save the function of the <code>User</code> in a variable like <code>var User = function(){...</code> is not a module... Please bear in mind I'm learning js. </p>