2 ms·
Yes, replace 'var' with 'let' and it ends up correctly scoped. var also gets scoped to the function (or in this case, the window if you just run this loop direc
by bigDinosaur 4y ago
Yes, replace 'var' with 'let' and it ends up correctly scoped. var also gets scoped to the function (or in this case, the window if you just run this loop directly), so you'll even be able to view the value 3 with window.i which is also unexpected. Always use let, I guess.