The outcome is determined by the content of your first()
and second()
functions. If there are asynchronous calls present, first()
might finish after second()
.
Consider this scenario:
function first(){
console.log("I'm first");
}
function second(){
console.log("I'm second");
}
first();
second();
This code will display:
I'm first
I'm second
However, if your first()
function includes an ajax call that takes 10 seconds to complete:
function first(){
$.ajax({
//--- blah blah
success: function(){
//--- success runs after 10 seconds
console.log("I'm first");
}
})
}
and you execute:
first();
second();
You will see:
I'm second
I'm first
For another illustration, check out this link.