gpt4 book ai didi

Javascript 提升 - David Shariff 测验

转载 作者:行者123 更新时间:2023-11-28 11:12:09 29 4
gpt4 key购买 nike

问题是,以下警报会发生什么:

function bar() {
return foo;
foo = 10;
function foo() {}
var foo = '11';
}
alert(typeof bar());

答案是,函数。

我的问题:

  1. bar()不是被它的返回值取代了吗?如果不是,为什么?
  2. 不是 foo = 10;被提升到顶部? (吊装)

最佳答案

你可以这样看:

function bar() {
var foo = function() {};
return foo; // function ends here
foo = 10;
foo = '11';
}

另外两个赋值语句没有发生。

关于Javascript 提升 - David Shariff 测验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26109087/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com