4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

超ざっくりと理解する無名関数(匿名関数)

Last updated at Posted at 2018-07-12

これは名前付き関数

function hello (name) {
 
       var msg = "hello" + name;
       return msg;
}

 var greet = hello("Taro") ;

console.log(greet);
//出力結果 "hello Taro"
 

こちらの関数には「hello」という名前が付いています。

これが無名関数

var hello = function(name) { 

            var msg = "hello " + name;

            return msg;
        };

        var greet = hello("Tom");

        console.log(greet);

関数を関数名と同じ変数に代入することで、関数を無名にできるのです。

イメージは以下のような感じでしょうか?

スクリーンショット 2018-07-13 7.19.31.png
※ちなみに同じ名前の変数じゃなくても問題ないです。

参考

4
2
0

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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?