Help us understand the problem. What is going on with this article?

[JavaScript][Node.js]メモ:アロー関数の文法

アロー関数(ES2015)の書き方。

f = () => console.log('Hello!')
f()  // Hello!
評価した値を返す
// 式(Expressions)の評価結果が戻り値になる
sum = (a, b) => a + b
r = sum(1, 2)
console.log(r) // 3
returnで値を返す
// {}で文(Statements)を作り、returnで値を返す
sum = (a, b) => { 
  return a + b 
}
r = sum(1, 2)
console.log(r) // 3
引数のカッコを省略
// 引数が一つの時のみカッコを省略可能(0個もしくは2つ以上のときは省略不可)
say = word => console.log(word + '!')
say('Yeah')  // Yeah!
即時関数
(() => console.log('Hello!'))() 
引数としてのアロー関数
arr = [1,2,3,4,5]

// かっこよくない
console.log(arr.map(function(e) { return e + 1 }))  // [ 2, 3, 4, 5, 6 ]

// かっこいい
console.log(arr.map(e => e + 1))  // [ 2, 3, 4, 5, 6 ]

リンク(mozilla)

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした