title: Understanding callback function purpose
body: <p>I realise this is more of a general question, but I've read through similar answers on here but I can't find more of an overview. I'm new to callbacks and I'm trying to understand when they should be used.</p>
  
  <p>The MDN web docs has this example;</p>
  
  <pre><code>function greeting(name) {
    alert('Hello ' + name);
  }
  
  function processUserInput(callback) {
    var name = prompt('Please enter your name.');
    callback(name);
  }
  
  processUserInput(greeting);
  </code></pre>
  
  <p>However I'm struggling to see how this is more beneficial than the following, where I'm not passing the greeting function as a parameter?</p>
  
  <pre><code>function greeting(name) {
    alert('Hello ' + name);
  }
  
  function processUserInput() {
    var name = prompt('Please enter your name.');
    greeting(name);
  }
  
  processUserInput();
  </code></pre>