LoginSignup
3
7

More than 5 years have passed since last update.

アロー関数を世界一わかりやすく説明

Last updated at Posted at 2019-03-11

アロー関数とは

最近導入された、関数の新しい書き方。
ざっくりいうと関数が簡単にかけるよってこと。

実際のコードの違い

function式 (今までの書き方):

const test = function(x) {return x * 2}

アロー関数 (新しい書き方):

const test = (x) => x * 2  //本体が単一の式
//または:
const test = (x) => { return x * 2 } //本体が文

補足

  • 引数が一つの時は、
const test = x => x * 2

このように()を省略しても良い

  • 引数がない場合は、()を省略してはいけない。
const test = () =>  {console.log(this)}

終わりに

thisの取り扱いの注意とかもありますが難しいので別記事で取り上げます。

3
7
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
3
7