$(function() {
foo1("text");
foo2("text");
})
function callback(func) {
func();
}
function foo1(bar) {
callback(function() {
console.log(bar); // "text"
bar = "derp";
console.log(bar); // "derp"
})
}
function foo2(bar) {
callback(function() {
console.log(bar); // undefined
var bar = "derp";
console.log(bar); // "derp"
})
}
Why is that declaration of var bar = "derp" undefining the parameter, that is accessed beforehand?