2
0

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.

JavaScriptの即時関数の書き方

Last updated at Posted at 2018-09-30

即時関数とは何ぞや?

関数を記述すると同時に実行すること

書き方

  var addition = (function (a,b){
    var result = a + b;
    return result;
  })(1,2);
  console.log(addition);

出力結果

3

以下の様に全体をカッコで囲んでも同じ

  var addition = (function (a,b){
    var result = a + b;
    return result;
  }(1,2));
  console.log(addition);

参考

[JavaScriptで即時関数を使う方法【初心者向け】]
(https://techacademy.jp/magazine/5530)
[JavaScriptで即時関数を使う理由]
(https://qiita.com/katsukii/items/cfe9fd968ba0db603b1e)

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?