函數聲明舉例:
function shenlu(type){
return type==="decloartion";
}
解釋:在js解析時,進行函數提升,因此在同一個作用域內,不管函數聲明在哪里定義,該函數都可以進行調用。
Eg:
shenlu("decloartion");//ture
function shenlu(type){
return type==="decloartion";
}
因為變量提升后的樣式為:
function shenlu(type){
return type==="decloartion";
}
shenlu("decloartion");
函數表達式舉例:
var shenlu=funciton(type){
return type==="expression";
}
解釋:函數表達式的值在js運行時才確定,並且在表達式完成后,該函數才能調用。
Eg:
shenlu("Expression");//false
var shenlu=funciton(type){
return type==="expression";
}
提升后:
var shenlu;
shenlu("Expression");
shenlu=function(type){
return type==="expression";
}
:
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。