title: javascript: getting incorrect variable being set when passed as an argument
body: <p>I have following code &amp; output. I don't understand why the function is receiving incorrect argument. Please provide pointers. </p>
  
  <pre><code>var tempAccounts = [];
  var i;
  for (i = 0; i &lt; accountIDs.length; i++) {
      var accountID = accountIDs[i];
      console.log("Log1:" + accountID);
      tempAccounts.push(function(callback){createTempAccount(accountID, callback)})
  }
  
  async.parallel(tempAccounts, function (error, results) {
      if (error) {
          sendError(error, "error creating temp acounts", res, logTag);
      } else {
          res.set('Content-Type','application/json');
          res.send(200, {});
      }
  });
  
  
  function createTempAccount(accountID, callback)
  {
    console.log("Log2:" + accountID);
    ...
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Log1: 1234
  Log1: abcd
  
  Log2: 1234
  Log2: 1234
  </code></pre>
  
  <p>What could be the issue here?</p>