mardi 6 octobre 2015

Interpreting output after using callback in javascript

I am new to javascript and I am trying to understand callbacks. I am not able to understand why 20 is getting printed before 10. My understanding is for a callback function like - func1(parameter,func2()) , func2() is the callback function, which gets executed after func1 executes with the "parameter" passed to func1. Is my understanding correct?

function timePass(length){

    console.log("finished after doing timePass for "+length +" seconds")
}

timePass(10,timePass(20));

OUTPUT BELOW:

finished after doing timePass for 20 seconds

finished after doing timePass for 10 seconds




Aucun commentaire:

Enregistrer un commentaire