title: Node.js - Argument in an anonymous function without passing it a variable?
body: <p>I come from a C/C++ background and I'm having real trouble trying to wrap my head around the syntax of node.js. Anyway, I found some code online to explain the difference between blocking and non-blocking code, and it's had me stumped for hours. I've tried searching and reading books but just can't find an answer to this. The example code retrieves a user ID from a database.</p>
  
  <p><strong>Blocking Version:</strong></p>
  
  <pre><code>function getUser(id) {
     var user = db.query(id);
     return user;
  }
  
  console.log('Name: ' + getUser(432).name);
  </code></pre>
  
  <p><strong>Non-Blocking Version (Node.js):</strong></p>
  
  <pre><code>function getUser(id, callback) {
     db.query(id, callback);
  }
  
  getUser(432, function (user) {
     console.log(user.name);
  });
  </code></pre>
  
  <p>I'm fine with the Blocking version because in that instance, the user ID is assigned to the variable <code>user</code>. What I just can't seem to understand is the <code>user</code> argument in the anonymous function. It seems that <code>user</code> just appears out of nowhere and then has instructions acted upon it, without any relationship to an existing variable. </p>
  
  <p>How does the program know what <code>user</code> is? How does it even make any connection with the user's ID? I honestly can't tell if it's my lack of knowledge of JavaScript/Node, or whether the person who wrote this code didn't bother to complete it. All I know is, this makes no sense in C/C++. </p>