考虑这两个稍微不同的提升版本......
mylocation = "dublin"
function outputPosition() {
alert(mylocation);
mylocation = "fingal" ;
alert(mylocation);
}
outputPosition();
这将输出“fingal”,然后是“fingal”
mylocation = "dublin"
function outputPosition() {
alert(mylocation);
var mylocation = "fingal" ;
alert(mylocation);
}
outputPosition();
这将输出“未定义”和“fingal”
为什么?