-4
案例1 - 如果我在变量声明前的console.log(variable)变量未定义。例如;javascript变量的怪异行为
// code
console.log(a);
var a ;
// output
undefined
案例2 - 如果我CONSOLE.LOG(变量)没有变量声明,我得到未捕获的ReferenceError:变量没有定义。
// code
console.log(a);
// output
Uncaught ReferenceError: a is not defined
但柜面的功能,我们可以调用一个函数它从来没有给任何问题之前或之后的函数定义。例如;现在
console.log(example());
function example(){
return 'test done';
}
console.log(example());
// output without any issue
我的问题是,什么是不确定和没有定义之间的差异。
请做更多的研究和谷歌周围它自动得到答案:) –
'var'和'function'声明被悬挂。欢迎来到JS。 – zzzzBov
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/var搜索“提升” –