I can't find the answer to this question on any other previously asked question.
This will alert 5 times, displaying the numbers 1 to 5.
for (i = 1; i <= 5; i++) {
alert(i)
}
This will alert 5 times, displaying the number 6 every time. I understand that it will display the same number 5 times but why does it display 6 instead of 5?
for (i = 1; i <= 5; i++) {
setTimeout(function(){
alert(i)
});
}