I was running following JavaScript:
var foo = function() {
var a = 3,
b = 5;
var bar = function() {
var b = 7,
c = 11;
a += b + c;
console.debug(d);
};
bar();
console.debug(c);
var d = 10;
};
foo();
Clearly, d
is not known to nested function bar
and c
is not known to external function foo
. But in developer tools, when I load my web page I get two different logs one by one:
undefined
Uncaught ReferenceError: c is not defined
Why are the errors different for the two cases? In my opinion both should have thrown simply thrown reference error if the corresponding variable is not known to them or is out of scope.