callback hell in node js code example

Example 1: callback function js

function greeting(name) {
  alert('Hello ' + name);
}

function processUserInput(callback) {
  var name = prompt('Please enter your name.');
  callback(name);
}

processUserInput(greeting);

Example 2: node js callback

function processData (callback) {
  fetchData(function (err, data) {
    if (err) {
      console.log("An error has occurred. Abort everything!");
      return callback(err);
    }
    data += 1;
    callback(null, data);
  });
}

processData(function (err, data) {
  if (err) {
      console.err(err);
  } else {
    console.log("Data: " + data);
  }
});

Tags:

Misc Example