JavaScript-4.2函数,变量作用域---ShinePans

来源:互联网 发布:mac视频下载插件 编辑:程序博客网 时间:2024/05/20 11:20
<html><head><meta http-equiv="content-type" content="text/html;charset=GB2312"/><title> 4.2 函数和变量作用域 </title><!--脚本部分--><script type="text/javascript">var v1,v2;v1=10;v2=20;function a(){var v2,v3;alert("v1="+v1+"\r\nv2= "+v2+"\r\nv3="+v3);v2=v3=40;function b(v3,v4){alert("v3 = "+v3+"\r\nv4="+v4);v2=v3=80;}b(v3);alert("v2="+v2+"\r\nv3="+v3);alert(v4);}a();</script></head><body style="overflow:auto;"></body></html>


函数外的变量在函数里面无需声明直接使用,函数里面声明的变量在函数外部是无效的.



3 0