函数调用javascript
我调用了helloworld,并用以下两种不同的方式对其进行了定义: 1) 可变的 2) 函数名为itseld函数调用javascript,javascript,function,alert,Javascript,Function,Alert,我调用了helloworld,并用以下两种不同的方式对其进行了定义: 1) 可变的 2) 函数名为itseld var helloWorld = function() { return '2'; } function helloWorld() { return '1'; } alert (helloWorld()); // This alert 2, but in absence of "var helloWorld = ....", it alert "1". 有人能解
var helloWorld = function() {
return '2';
}
function helloWorld() {
return '1';
}
alert (helloWorld()); // This alert 2, but in absence of "var helloWorld = ....", it alert "1".
有人能解释一下为什么它调用var helloWord=?而不是函数helloWorld()
谢谢 它为什么调用var helloWord=?而不是函数helloWorld()
因为功能
定义将提升到顶部。而且作业仍然在同一个地方。因此,它正在被覆盖
解释器就是这样看待代码的
function helloWorld() {
return '1';
}
var helloWorld;
//the above function is getting overridden here.
helloWorld = function() {
return '2';
}
alert (helloWorld());
为什么它调用var helloWord=?而不是函数helloWorld()
因为功能
定义将提升到顶部。而且作业仍然在同一个地方。因此,它正在被覆盖
解释器就是这样看待代码的
function helloWorld() {
return '1';
}
var helloWorld;
//the above function is getting overridden here.
helloWorld = function() {
return '2';
}
alert (helloWorld());
读这个:读这个:这里有一个关于变量和函数提升的很好的演示:也有一篇关于这个的文章。这里有一个关于变量和函数提升的很好的演示:也有一篇关于这个的文章。