<script>
function test(){
    testd = "Hello";
}
test();
alert(testd);
</script>

当未定义的时候  “tsestd”这个未声明的变量自动成为全局变量声明

<script>
function test(){
    var testd = "Hello";
}
test();
alert(testd);
</script>

当在函数内部声明了该变量 此时 “testd is not defined”。

 

posted on 2017-03-23 14:07  liris  阅读(3234)  评论(0编辑  收藏  举报