Has this happened to you before? If so, read on to learn how to solve this problem.
How do I use it ?
The easiest way to use callback is as follow:
//Create callback function
var d = 1;
callback(d); //<---where the magic happens
//Call the callback function like this:
//data is here is value of variable d
//in this case it will be 1
When To Use Regular Vs Callback Function?
When you are having to deal with any kind of calculation locally, always use a function that returns a value.
var d = 100;
//Call the function like this:
var v1 = reg_func();
When you are making a call to an external source, always use a callback function, because that way your code will not continue until that process of external source has finished doing whatever it needs to do.