First :
function A() {
for (var i = 0; i < 10; ++i) {
//...
}
console.log(i); //i is undefined
// i dont get global i
for (i = 0; i < 10; ++i) {
//...
}
}
When i execute A() , i donot get global var i . But this:
function B() {
// i get global i
for (i = 0; i < 10; ++i) {
//...
}
}
When i execute B() , I get global i . So why i cannot get the global when i execute A() ?