var a = 1;
function a(x){}
alert(a);
输出 1
function a(x){}
alert(a);
输出 function a(x){}
能解释为什么是这样的输出吗
不明白预编译的过程,和语法树,有没有好点的博文,求链接。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
已此方式宣告的function將會獲得提升
如此的則不會
所以...
1.宣告a
2.宣告a為function
3.將a賦值 1
最終a為1
1.宣告a
2.宣告a
3.將a賦值 1
4.將a賦值 function (x) {}
最終a為 function (x) {}