var a = function () {….} :Expression
・這種寫法應該比較穩定
var hereOrThere = function () { // 表達式
return 'here';
};
console.log(hereOrThere()); // console'here'
hereOrThere = function () {
return 'there';
};
(聲明提前)
var hereOrThere //聲明提前
hereOrThere=function () { // 表達式
return 'here';
};
console.log(hereOrThere()); // console 'here'
hereOrThere = function () {
return 'there';
};
function a() {….}:statement
- function a () {…} 是一種聲明,因此會提前
function hereOrThere() {
return 'here';
}
console.log(hereOrThere()); // console 'there'
function hereOrThere() {
return 'there';
}
(聲明提前)
function hereOrThere() {
return 'here';
}
function hereOrThere() { //聲明提前
return 'there';
}
console.log(hereOrThere()); // console 'there'
推薦文章:JavaScript中對變量和函數聲明的“提前(hoist)”