I am trying to pull a variable's value from a callback function. What am I doing wrong here?
var storyList = [];
var storyTemp ={};
// get list of all stories
db.getAllStoriesSet(function(err, reply) {
if (err) throw err;
else {
storyList = reply;
console.log("storylist inner: " + storyList);
};
});
console.log("storylist outer: " + storyList);
in the above code, I am expecting the inner and outer storylist values to be same. however the outer storyList value still comes as a null list.
EDIT: to add to the question. I have initialized a variable storyList outside the async function. i am then taking the reply from the async function and putting it in the variable storyList. I was hoping to cheat my way out of the async pit of slow and brutal death that I have apparently dug for myself. shouldnt it have worked?