Since I'm not very experienced with regard to Javascript, I'm kinda baffled about the function order.
In the following example I'd expect console.log() to be processed AFTER wait() is finished.
function wait() {
setTimeout(function () {
console.log("wait " + new Date().getTime());
}, 3000);
}
wait();
console.log("global " + new Date().getTime());
The console shows those values:
global 1499993535591 wait 1499993538592
Why is the second function being processed before the first one isn't even completed?
This is causing me some problems when I fill an array inside a function and need to do something with it outside of that function, because it's still empty then.