【发布时间】:2020-06-06 08:41:39
【问题描述】:
考虑下面我在我的 chrome 浏览器控制台中运行的代码:
var x = "hello";
let foo = function(){
console.log("hi");
};
console.log(x); // hello
console.log(foo()); //hi
console.log(window.x); // hello
console.log(window.foo()); // Error
如果我使用var foo =... 而不是let foo = ..,那么这将有效。为什么 ?
【问题讨论】:
-
因为
let是这样定义的。
标签: javascript dom