var box = document.querySelector(".box");
for (var i = 0; i < 10; iPP) {
var li = document.createElement("li");
li.innerHTML = i;
box.appendChild(li);
li.addEventListener("click",function(){
console.log(i);
})
}
this code clicks on the newly produced li tag, which is all 10. The elevation book says that the closure can only get the last value of any variable in the function. I have understood it for a long time, but I don"t understand why.
the second question is, why does setting the type of I to let show normal click? I know that let is the concept of block-level scope, so why does block-level scope display normally?
some of them have been entwined. Please explain. Thank you very much.