All I am trying here is to access the local variable 'htmlrows' outside the function but it seems its not that easy with node.js.
var htmlrows;
query.on('row', function(row) {
console.log("%s |%s |%d", row.empid,row.name,row.age);
htmlrows += "<tr><td>" + row.empid + "</td><td>" +row.name + "</td><td>" +row.age + "</td></tr>";
});
console.log("htmlrows outside function");
console.log(htmlrows); // console log prints 'undefined'.
Could you please let me know how to access 'htmlrows' outside the function?
Thanks much in advance
endevent in the instance ofEventEmitterwhich isquery(this is typical):query.on('row',function(row){...htmlrows += "...";}).on('end',function(){console.log(htmlrows);});