0

I would like to ask you to explain one thing to me. I just started learning a concept of "Asynchronous Programming" in JavaScript but for some reason I struggle to "visualize" this code in my head.

function add(a, b, callback) {
  callback(a + b);
}

add(10, 10, function(sum) {
  console.log(sum); 
});

It's an extremely simple piece of code and yet I can't get around it. I mean, I know that it uses a callback via anonymous function but could you please explain each step and its order after we call the function?

DmitryDev
  • 123
  • 3
  • 7
  • I recommend you to read this article [Async JavaScript: From Callbacks, to Promises, to Async/Await](https://ui.dev/async-javascript-from-callbacks-to-promises-to-async-await/). Callbacks are explained in the first chapter – sebastian-ruehmann Jun 18 '20 at 20:42

0 Answers0