LoginSignup
8
10

More than 5 years have passed since last update.

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

Last updated at Posted at 2015-09-26

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

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{}
// 関数式

と呼ぶそうです。

8
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
10