変数宣言の巻き上げ、関数の巻き上げ
by s_hiroshi
JavaScript
// 巻き上げ処理
// 変数
// 変数は巻き上げ処理がされる。
// 関数
// 関数宣言文は巻き上げ処理がされる。
// 関数宣言式は巻き上げ処理されない。
// 「変数」の巻き上げ処理が行われる。
// 関数宣言文は同時に関数の巻き上げ処理も行われる
// 値はundefined
// foo is not defined, bar is not definedではない
console.log(foo); // foo(value)
console.log(bar); // undefined * bar is not definedではない
// 関数宣言文は「関数」の巻き上げ処理が行われる。
console.log(foo('Foo')); // Foo
// 関数宣言式は「関数」の巻き上げ処理が行われない。
// bar(); // bar is not a function
// 関数宣言文
function foo (value) {
return value;
};
// 関数リテラル
var bar = function (value) {
return value
}