title: What function gets put into EventLoop in NodeJs and JS
body: <p>I've been reading some NodeJs articles in order to understand its async nature during which I found this and really liked it <a href="http://code.danyork.com/2011/01/25/node-js-doctors-offices-and-fast-food-restaurants-understanding-event-driven-programming/" rel="noreferrer">Node.js, Doctor’s Offices and Fast Food Restaurants – Understanding Event-driven Programming</a></p>
  
  <p>There is a thing called <code>EventLoop</code> that is FIFO based queue. They say when an async function gets hit, it gets put to EventLoop and will continue to get executed over there. </p>
  
  <p>I am little confused here. For example it is said <a href="http://code.tutsplus.com/tutorials/event-based-programming-what-async-has-over-sync--net-30027" rel="noreferrer">here</a>:</p>
  
  <blockquote>
    <p>In actuality, async functions like setTimeout and setInterval are
    pushed onto an queue known as the Event Loop.</p>
  </blockquote>
  
  <p>and in the same article:</p>
  
  <blockquote>
    <p>The Event Loop is a queue of callback functions. When an async
    function executes, the callback function is pushed into the queue. The
    JavaScript engine doesn't start processing the event loop until the
    code after an async function has executed.</p>
  </blockquote>
  
  <p>But it is different than this image:</p>
  
  <p><img src="https://i.stack.imgur.com/BTm1H.png" alt="enter image description here"></p>
  
  <p>Let's look at the following example:</p>
  
  <pre><code>console.log("Hello,");
  setTimeout(function(){console.log("World");},0);
  </code></pre>
  
  <p>So from what I understand from those different explanations, </p>
  
  <ol>
  <li>First one says <code>function(){console.log("World");}</code> part of the <code>setTimeout()</code> function, that is the callback, will be put in EventLoop. Once the <code>setTimeout</code> is done, it will execute the <code>EventLoop</code> as well.</li>
  <li>The other one says, the whole thing <code>setTimeout(function(){console.log("World");},0);</code> will be put the EventLoop and will get executed...</li>
  </ol>
  
  <p>I am confused even more now. It should be something simple but I guess a good but simple explanation would be nice for me for the following questions:</p>
  
  <ol>
  <li>Which one of the aforementioned things is true?</li>
  <li>What is EventLoop? An analogy, a real thing with methods, objects, etc?</li>
  <li>If I would like to implement a similar thing as EventLoop from scratch, how would it look like simply? Perhaps some code would be nice to see.</li>
  </ol>