What is the scope of JS variables in anonymous functions
- by smorhaim
Why does this code returns $products empty? If I test for $products inside the function it does show data... but once it finishes I can't seem to get the data.
var $products = new Array();
connection.query($sql, function(err, rows, fields) {
if (err) throw err;
for(i=0; i< rows.length; i++)
{
$products[rows[i].source_identifier] = "xyz";
}
});
connection.end();
console.log($products); // Shows empty.