I noticed an interesting result from JSLint while researching a codereview question. JSLint complained that a variable was used before it was defined. Here is a shortened version of code that produces the same result:
(function () {
try {
var a = 0;
throw { name: "fakeError" };
} catch (e) {
a = 1;
}
}());
My understanding of JavaScript says that the above code should be equivalent to:
(function () {
var a;
try {
a = 0;
throw { name: "fakeError" };
} catch (e) {
a = 1;
}
}());
and indeed, neither example causes a
to exist in the global scope when run through Firebug. I took a look at section 12.14 of the ECMA-262 spec, but I don't see anything that would lead me to think the functions should be treated differently. Is this just a bug in JSLint, or are the two expressions different in some functional way?