求教,请问最后 alert 为什么不是 2 ? var a = 3 ; 执行到这里的时候,都发生了什么!!!
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Basic1</title>
</head>
<body>
<button onclick="doit();">alert</button>
<script>
var a = 10;
function sth(){
console.log(a);//undefine
a=2;
console.log(a);//2
if(a >0){
var a = 3;
console.log(a);//3
}
}
function doit(){
sth();
alert(a);//alert 10
}
</script>
</body>
</html>