0
1

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 3 years have passed since last update.

40 代おっさん GASの関数(関数リテラル,アロー関数)について学ぶ

Posted at

本記事ついて

本記事は プログラミング初学者の私が学習していく中でわからない単語や概要をなるべくわかりやすい様にまとめたものです。
もし誤りなどありましたらコメントにてお知らせいただけるとありがたいです。

関数

関数とは
一連の処置をまとめたもの

定義方法
・function文による関数の宣言
https://qiita.com/kou1121/items/f7be2dc115b84a42f296
・関数リテラル
。アロー関数

関数リテラル

構文

function ( 仮引数1, 仮引数2, ...){
  //処理
};

関数宣言とほとんど同じですが、関数名を記述していない。
無名関数などと言われる。

関数式の最期にセミコロンが必要となる。

お試し

const toshiki_ = function() {
  console.log('利樹大好き');
};

function saytoshiki() {
  toshiki_();
  console.log('利樹もパパ大好き');
}

アロー関数

関数リテラルを短縮したもの

構文

(仮引数1, 仮引数2, ...) => {
  //処理
}

お試し

const toshiki_ = () => {
  console.log('利樹大好き');
};

function saytoshiki() {
  toshiki_();
  console.log('利樹もパパ大好き');
}

仮引数が一つの場合はもっと簡略化できる。

構文

仮引数1 => {
  //処理
}

さらにステートメントが一つの場合は、もっと簡略化

(仮引数1, 仮引数2, ...) => ステートメント

わらにステートメントが一つかつreturn文である場合は

(仮引数1, 仮引数2, ...) => ステートメント

お試し

function toshiki() {
  console.log(`利樹のBMI: ${bmi_(18,100)}`);
}

const bmi_=(weight,height) => weight/(height/100)/(height/100);

参考資料

https://www.amazon.co.jp/s?k=google+apps+script+%E5%AE%8C%E5%85%A8%E5%85%A5%E9%96%80&adgrpid=110264232688&gclid=CjwKCAiA9aKQBhBREiwAyGP5lSl7AJJLCvOEHb4wQgMlyqW1fll5X8GDTT_Rkd1_soUAyIPMXQr26hoClHEQAvD_BwE&hvadid=553833563682&hvdev=c&hvlocphy=1009076&hvnetw=g&hvqmt=b&hvrand=4378489642044417389&hvtargid=kwd-594191211348&hydadcr=4106_13159878&jp-ad-ap=0&tag=googhydr-22&ref=pd_sl_2x1owglv0s_b_p52

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?