<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
//变量作用域
var x=1;
function test(){
document.write('函数体内x的值为:'+x+'<br/>'); //undefined,x值取下面的,但是取不到值
var x=19;
document.write('函数体内对x重新赋值,此时x的值为:'+x+'<br/>'); //19
}
document.write('函数体外x的值为:'+x+'<br/>'); //1
test();
document.write('x的值为:'+x+'<br/>'); //1
//document.write('<hr color="red"/>');
</script>
</body>
</html>
转载于:https://www.cnblogs.com/d-z-j-boke/p/9543944.html