title: Node JS Code Execution
body: <p>I'm getting slightly annoyed now after reading many different articles on how to write proper code in node js.</p>
  
  <p>I would just like some clarification on whether I'm correct or not with each of these statements:</p>
  
  <ul>
  <li>Code is executed synchronously</li>
  <li>A for loop or while loop etc. will be executed asynchronously</li>
  <li>By doing the code below isn't proper asynchronous:</li>
  </ul>
  
  <p>L</p>
  
  <pre><code>function doSomething(callback) {
      // doing some code
  
      // much much code
  
      callback();
  }
  </code></pre>
  
  <p>The reason that people are saying that this won't work properly is that code is executed asynchronously, so the callback won't be fired off at the end of the code it will all be executed at once. </p>
  
  <p>So for example if you were filling some object by doing some stuff and you wanted to post that full object back through the callback it doesn't work because it will all be executed at the same time.</p>