title: Explanation about Javascript function inside function?
body: <p>I've been learning about js for a while, I almost understand about its main concepts such as prototype, oop ... however I can't understand how this works:</p>
  
  <pre><code>User.findOne().where('socialid').equals(id).where('socialnetwork').equals(snw).exec(function (arr,data) {
      if(data){
      res.send(data);
      }
  });
  </code></pre>
  
  <p>What I don't understand is how <strong>data</strong> and <strong>arr</strong> variables are passed to the <em>function</em> inside the <em>exec()</em> function. Is it a closure ? Can anybody give a more simple and intuitive example how it execute behind the scene ?</p>
  
  <p><strong>EDITED</strong>: actually, I do understand the callback behavior, what I can't understand is <strong>data</strong> supposed to be a result by <strong>User.findOne()....</strong> not from inside the callback function of <strong>exec()</strong> and it only passed the new function to the <strong>exec()</strong> as I can see in the code.</p>
  
  <p>Thank you so much</p>