LoginSignup
0
1

More than 1 year has passed since last update.

JS 関数式のメリットとは?

Posted at

Q.関数を定数に代入するとなにがいいのか?

①関数宣言:関数を定義して、関数名で呼び出す方法

function 関数名(引数){
  処理
}

関数名(引数);

②関数式:定数に関数を値として代入し、後からその変数を呼び出す方法

const 定数 = function(引数) {
  処理
}
定数名(引数);

A.関数名が不要(無名関数というらしい)

但し、①は関数の呼び出しが定義より前に記述されていても実行される。②は実行されない。

今の時点では(エラーが出るまでは)②を使っていこうと思った。
(理由は関数名を考えなくていいから)

参考URL

0
1
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
0
1