title: What's the best practice for function callback structure?
body: <p>Which function callback structure is the best to use in Javascript and why? I have seen these two options use quite a lot. Are there any more?</p>
  
  <p><br>
  <strong>Option A:</strong></p>
  
  <pre><code>// DECLARATION
  function funcA(required, success, error, options){
  
    // if there is an error in your function return 
    // and run error function
    if(errorHappens){ return error('an error') };
  
    // if no error happened: run the success function
    success('all good here is your var back', required);
  }
  </code></pre>
  
  <p>.  </p>
  
  <pre><code>// USAGE
  funcA('this is required', function(result){
  
    // all good, do something with the result :)
  
  },
  function(error){
  
    // tell the user about the error
    alert('error happened')  
  },{
    optionalThing: ':-)'
  });
  </code></pre>
  
  <p><br>
  <strong>Option B:</strong></p>
  
  <pre><code>// DECLARATION
  function funcB(required, callback, options){
  
    // if an error happens run the single callback with
    // the err param populated and return
    if(errorHappens){ return callback('an error') };
  
    // if no error happened: run the callback with 'null'
    // as the error param.
    callback(null, 'this is a result');
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>// USAGE
  funcB('this is required', function(err, result){
    if(err){ return alert('error happened') };
  
    // all good do something with the result :)
  
  },{
    optionalThing: ':-)'
  }
  </code></pre>