9
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

function hoge() と var hoge = function()の挙動の違い

下記、挙動の違いがありました。

hoge

hello(); // "hello" :関数宣言前でも実行可
// byebye();  TypeError: undefined is not a function :実行不可   

function hello(){
    console.log('hello');
}

var byebye = function(){
    console.log('byebye');
};
byebye();  // "byebye" :関数式後なので実行可

たまに実行できなかった謎がとけました!

ちなみに

hoge

function hoge() 
// 関数宣言

var hoge = function{}
// 関数式

と呼ぶそうです。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
9
Help us understand the problem. What are the problem?