I am trying to get a better fundamental understandings of JavaScript's closure
say we have these two different scenarios in Node.js
function A(){
console.log(data); //this should give us a null pointer
}
module.exports = function(data){
return A;
}
versus
module.exports = function(data){
return function A(){
console.log(data); // variable "data" will be remembered
};
}
why is it that in the first case the variable "data" is not remembered but in the latter case it is "remembered" by the closure?
I am sure in some language somewhere, declaring a function and referencing a function might both remember the variables in the outer function, but I guess I want to better understand the difference.