样式
代码
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="huyiwei">
<title>全局变量和局部变量使用实例</title>
</head>
<body>
<h4>全局变量和局部变量使用</h4>
<script type="text/javascript">
var test1 = 100,test2 = 100;//定义全局变量
function checkScope( ){
var test1 = 200;//定义局部变量
test2 = 200; //给全局变量再次赋值
document.write("局部变量test1的值为"+test1);
document.write("<br/>");
}
checkScope( );
document.write("全局变量test1的值为"+test1);
document.write("<br/>");
document.write("全局变量test2的值为"+test2);
</script>
</body>
</html>