lgwebdream / FE-Interview

🔥🔥🔥 前端面试,独有前端面试题详解,前端面试刷题必备,1000+前端面试真题,Html、Css、JavaScript、Vue、React、Node、TypeScript、Webpack、算法、网络与安全、浏览器
https://lgwebdream.github.io/FE-Interview/
Other
6.82k stars 896 forks source link

Day189 写出代码正确执行结果,并解释原因 #1006

Open Genzhen opened 3 years ago

Genzhen commented 3 years ago
function test() {
  console.log("out");
}
(function () {
  if (false) {
    function test() {
      console.log("in");
    }
  }
  test();
})();

每日一题会在下午四点在交流群集中讨论,五点小程序中更新答案 欢迎大家在下方发表自己的优质见解 二维码加载失败可点击 小程序二维码

扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。

luuman commented 2 years ago

test is not a function

luuman commented 2 years ago

立即执行函数 内部定义的变量不会和外部的变量发生冲突,俗称“匿名包裹器”或“命名空间”

geweidong commented 2 years ago

立即执行函数内部声明test,会存在变量提升。