Quick question, because one thing confused me today. Below is piece of JavaScript code:
var a = [1, 2, 3, 4];
function init() {
console.log(a);
if (false) {
var a = [9, 8, 7];
}
}
init();
This simple code logs "undefined" in JS console. I found that the reason for this is 5th line:
var a = [9, 8, 7];
Without word var inside that condition, it will log correct result [1, 2, 3, 4].
My question here is: why JavaScript interpreter takes into consideration piece of code which never will be executed?
Example to play with: http://jsfiddle.net/5DPCz/