Difference between let, const and var in easiest way with Guarantee…
Arslan shakoor

This has me, Im still confused as to how the console log is 5.

for (var i = 0; i < 5; i++) {
var btn = document.createElement('button');
btn.appendChild(document.createTextNode('Button ' + i));
btn.addEventListener('click', (function() {
{ console.log(i); };
Like what you read? Give Gregg Od a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.