In the following example:
i
is defined;j
is undefined but declared;k
is undeclared thus causing error;indx
is hoisted to the top of the function.
(function () {
var i = 1;
var j;
console.log("i : " + i); // i : 1
console.log("j : " + j); // j : undefined
//console.log("k : " + k);// ReferenceError: k is not defined
console.log("indx : " + indx);// indx : undefined
for(var indx = 0; indx < 3; indx++){
console.log("indx in for : " + indx);// indx in for : 0|1|2
}
console.log("indx after for : " + indx);// indx after for : 3
}())