Why let the behavior of the var in the cycle the same?

for (var iIi = 0; iIi < 3; iIi++) {
 console.log(iIi); // 012 . In one video it was said that it should be 123, because the alleged sight of one in the () and {} if you use var . The language has changed in a year and a bit?
}
for (let jJj = 0; jJj < 3; jJj++) {
 console.log(jJj); // 012 
}


What is the difference then let var?
March 23rd 20 at 18:50
2 answers
March 23rd 20 at 18:52
Solution
In the video certainly said about asynchronous functions. View this:

for (var iIi = 0; iIi < 3; iIi++) {
 setTimeout(() => console.log(iIi), 0);
}
for (let jJj = 0; jJj < 3; jJj++) {
 setTimeout(() => console.log(jJj), 0);
}
while I have to such concepts have not yet reached, but it seems like the result is different now , thanks) - edythe_Jast44 commented on March 23rd 20 at 18:55
March 23rd 20 at 18:54
Solution
with this announcement, `var` will float up, meaning it will be available outside the loop, and `let` just inside the loop

Find more questions by tags JavaScript