I came accross to a problem where I can not understand how the order of the code is being executed. Let's say I have:
console.log("0");
foo();
console.log("1");
function foo(){
console.log("2");
jsonfile.readFile('test.json', function(err, obj){
console.log("3");
});
console.log("4");
}
The output of the above program is "0 2 4 1 3" when I was expecting "0 2 3 4 1".
Why this is happening?