Considering given code
function foo() {
var bar = [];
asyncRequest.get(function(data) {
bar = data;
});
return bar;
}
how do you return bar when it's filled with data from callback and not before? In 50% cases return is reached earlier then callback finishes and empty array is returned.