I came across the following issue:
function Parent(value) {
var callback = function() {
console.log(value);
//actually the following line was found in the code
var value; //<- hoisting, takes effect first
}
callback();
}
Parent(); //undefined
Parent('Wow!'); //undefined, closure value was lost?!
Both Parent calls logged 'undefined' message, but I really expected to see 'Wow!' value on the second call.
Issue can be reproduced here: http://jsfiddle.net/5tgsj37e/3/
Related question: Why does this closure-scoped variable lose its value?