函數表達式和函數聲明
函數聲明舉例:
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";
}
: