1

In Javascript call back methods, the run time does not wait until the method completes. The execution goes to the next function while the previous one still executes. Can anyone please help me to understand how Javascript does this ?

For example:

function method1(){
   console.log("Printing from method1..");
}

T.get('search/tweets', params, function(err, data, response) {
  if(!err){
    // This is where the magic will happen
  } else {
    console.log(err);
  }
});         // first call

method1();   //second call

Above method1 finishes execution before get() finishes. how Javascript identifies it can go to method1() before get() ?

Is it something whenever a function is passed as one of the arguments to a function call, the control invokes the function and then goes to invoke the next function ?

In other languages (like: c, c++ and Java), next function won't be executed until the previous one finishes.

Thanks!

user3103957
  • 492
  • 2
  • 10

0 Answers0