I come from Java and find this language similar to Java in many places. recently I went across a program where I referenced variable before the variable declaration in the if-else block, why is this not throwing a syntax error?
function add(x, y, toDbl) {
result = 0;
if (toDbl)
var result = (x + y) * 2;
else
var result = (x + y);
return result;
}