for循环中定义的变量在for循环体外也有效
<script>
(function(){ var a = 111;
for(var i=0;i<5;i++){
var carl = 111;
console.log(i);
}
alert("carl is:"+carl);
})(); </script>
结果:
carl is:111
for循环中定义的变量在for循环体外也有效
<script>
(function(){ var a = 111;
for(var i=0;i<5;i++){
var carl = 111;
console.log(i);
}
alert("carl is:"+carl);
})(); </script>
结果:
carl is:111