Javascript code is generally asynchronous, to ensure code execution order generally callbacks are used, a function in a library may look like this:
function doWork(params, callback){
//do stuff
//when done call the callback function
callback()
}
This allows you to use this function and pass a function to be called when this function has finished doing what it needs to do.
doWork(params, function() {
//this code is not executed until doWork has completed and called its callback
})
Have a look at the library you are using they probably use callbacks