Hi,
In the Handling common JavaScript problems article it’s written that in bad-for-loop.html, i
is reported to be 11 when the paragraph is clicked.
for(let i = 1; i <= 10; i++) {
const para = document.createElement('p');
para.textContent = 'This is paragraph ' + i + '.';
document.body.appendChild(para);
para.onclick = function() {
alert('Hello from paragraph ' + i + '!');
}
}
I tried it on 3 modern browsers (Firefox, Chrome and Edge) and i
is reported to be the correct number of the paragraph and not 11.
On Internet Explorer it’s indeed reported to be 11.
Any explanation will be appreciated.
Thanks,