re: What dev topic do you think you should understand, but don't? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Indeed it does. Functions in a callback chain finish inside to outward. When doing async API calls, I've usually been saving the response (after JS...

You can make each callback function return the function before it - like this:

const topLevelData = funcWithCallback(someVar, () => {
  return anotherFuncWithCallback(someOtherVar, () => {
    return yetAnotherFuncWithCallback(aDifferentVar, () => {
      return "result";
    });
  });
});

And then those functions would need to return their callback:

function yetAnotherFuncWithCallback(data, callback) {
  doSomethingWithData(data);
  return callback();
}

Then you should have it outside of the callbacks!

Wow thanks for taking the time to explain that. Much clearer now!

code of conduct - report abuse