As these two discussions says:
javascript global variable with 'var' and without 'var' [duplicate]
Difference between using var and not using var in JavaScript
There should be no different when global variable with 'var' or not.
However, the following two snips of code get different results.
First One:
if(h == undefined){
h = 4;
}
Second One:
if(h == undefined){
var h = 4;
}
With the first one, I will get the error message: "ReferenceError: h is not defined."
However the second one is fine.
The really weird thing is that var h = 4;
is after h == undefined
but it let global variable can be initialized somehow.