title: Nodejs, callback function
body: <p>I am trying to understand callback function concept.</p>
  
  <p>Please explain what is the difference between two snippets of code</p>
  
  <pre><code>  //callback function
  
  function greeting(name) {
      console.log('Hello ' + name);
  }
  
  function processUserInput(callback) {
      var name = "Johny1";
      callback(name);
  }
  
  processUserInput(greeting);
  </code></pre>
  
  <p>and 2nd one</p>
  
  <pre><code>function greeting(name) {
      console.log('Hello ' + name);
  }
  
  function processUserInput() {
      var name = "Johny2";
      greeting(name);
  }
  
  processUserInput();
  </code></pre>
  
  <p>why someone uses the callback function when the same thing can be achieved by simple function?</p>