<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<script>
window.onload=function(){
var scope="global";
function t(){
console.log(scope);
var scope="local";
console.log(scope);
}
t();
}
</script>
</body>
</html>
上面的这一段代码,第一个打印的是undefined,第二个打印的是local,这是为什么啊,不是说通过作用域链可以向上访问的吗,那为什么第一次打印的时候会是undefined。
慕神8447489
相关分类