To me it seems it's only happening in the following scenario, when you use a not declared variable with the same identifier in alternative parts of a javascript script, e.g.:
if (true) {
v1 = 'a';
} else {
v1 = 'b';
}
while this is working fine:
var v1;
if (true) {
v1 = 'a';
} else {
v1 = 'b';
}