3 ms·
JS performs "variable hoisting", so your example is interpreted as: function(){ var i; … for(i=0; … It has surprising side effects: alert(i); var
by pornel 16y ago
JS performs "variable hoisting", so your example is interpreted as:
function(){ var i; … for(i=0; …
It has surprising side effects:
alert(i);
var i;
works and outputs "undefined", which is value of the variable i that is defined.
alert(k);
var i;
This is an error, and will fail to execute because of undefined variable.