36
26

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.

JSのアロー関数のreturnの書き方いろいろ

Posted at

##普通のJSで書くと


var multiplication = function(x,y){
	return x * y;
};
multiplication(2,10);

##ES6のアロー関数で書くと

let multiplication = (x,y) => {
	return x * y;
}
multiplication(2,10)

###さらに戻り値がそのままならreturnが省略できる

let multiplication = (x,y) => (
	x * y
)
multiplication(2,10)

###さらにさらに1行なら()もいらない

let multiplication = (x,y) => x * y
multiplication(2,10)

##引数の有無でも書き方が違う

// 引数が一つなら
let multiplication = x => x * x
multiplication(2)

// 引数が二つ以上なら
let multiplication = (x,y) => x * y
multiplication(2,10)

// 引数がない場合
let multiplication = () => 2 * 10
multiplication()
36
26
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
36
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?