javascript变量作用域2013-04-11javascript变量作用域只有两种情况:全局作用域、函数作用域没有代码块作用域,因而要养成一处声明全部变量的编程习惯(文件头部、函数头部)。
function test(){ var abc="123"; efg="456"; put("in test abc="+abc); put("in test efg="+efg); } function test1(){ var abc; put("in test1 abc="+abc); } var abc="abc";var efg="efg";test1();put("before test abc="+abc);put("before test efg="+efg);test();test1();put("after test abc="+abc);put("after test efg="+efg);{ var abc="www";put("in block abc="+abc);}put("out block abc="+abc);调试信息:in test1 abc=undefinedbefore test abc=abcbefore test efg=efgin test abc=123in test efg=456in test1 abc=undefinedafter test abc=abcafter test efg=456in block abc=wwwout block abc=www本文出自 “iData” 博客,请务必保留此出处http://idata.blog.51cto.com/4581576/1100248