Sign in
Log inSign up

Confusion between var and let

Default profile photo
Anonymous
·Mar 7, 2018
const cloudCount = () => {
let i = 2;
console.log(i); // 2
for (let i = 0; i < 10; i++) {
console.log(i); // All numbers from 0 to 9
}
};

cloudCount();
console.log(i);//  output is undefined

// here the code is working fine ,even though I have declared i two times within the same scope but when I replace let i in for loop with var i then is giving error.