`
和谐是美
  • 浏览: 49179 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

js 作用域

 
阅读更多

<html>

<head>
<script type="text/javascript">

//全局变量foo
var foo = "test";
if(true){
    foo="new test";
}
alert(foo=="new test");
function test(){
    var foo="old test"
}
//调用时,foo 驻留在函数的作用域里
test();
alert(foo=="new test");// true
</script>
<body>


</body>

</head>

</html>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics