Last active
January 26, 2016 09:19
-
-
Save whizzter/d7e721fbf89253fdd59a to your computer and use it in GitHub Desktop.
Var and let
This file contains hidden or 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
<!-- find the bug --> | |
<html> | |
<head> | |
<script> | |
"use strict"; | |
function iny() { | |
let body=document.getElementById("bod"); | |
let nums=[1,2,3]; | |
for (let lnum of nums) { | |
let but=mkButton("Let button"+lnum); | |
but.onclick=function() { | |
alert("Clicked "+lnum); | |
} | |
} | |
for (var vnum of nums) { | |
var but=mkButton("Var button "+vnum); | |
but.onclick=function() { | |
alert("Clicked "+vnum); | |
} | |
} | |
function mkButton(name) { | |
var but=document.createElement("input"); | |
but.type="button"; | |
but.value=name; | |
body.appendChild(but); | |
return but; | |
} | |
} | |
</script> | |
</head> | |
<body onload="iny();" id="bod"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment