getTodos(function(){
console.log(todos)
});
function getTodos(callback) {
setTimeout(function() {
const todos = [{title:"Walk the dog"},{title:"Feed the cat"}];
callback();
},1000);
};
I thought the callback function when executed after 1 sec will be able to see the todo const. But the interpreter tells me todos is not defined
Am i missing something here?
To add more knowledge that i learnt from a fellow programmer here: "Parent scope is not where its called but where its defined"
var todos = [{title:"Curb the dog"},{title:"Tickle the cat"}]
var cb = function(){
console.log(todos);
}
getTodos(cb);
function getTodos(callback) {
setTimeout(function() {
const todos = [{title:"Walk the dog"},{title:"Feed the cat"}];
callback();
},1000);
};