Created
January 14, 2020 07:14
-
-
Save tiptopcoder/668313573c68335def8de62481d750ef to your computer and use it in GitHub Desktop.
How good your JS?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addLinks () { | |
for (var i=0, link; i<5; i++) { | |
link = document.createElement("a"); | |
link.innerHTML = "Link " + i; | |
link.onclick = function () { | |
alert(i); | |
}; | |
document.body.appendChild(link); | |
} | |
} | |
// expect: alert according to i | |
// actual: alert 5 | |
window.onload = addLinks; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment