0
0

More than 1 year has passed since last update.

Javascript

Last updated at Posted at 2023-01-16
// returnがなくても返るケース
const hoge = () => ({a:1, b:2});

// returnが必要なケース
const fuga = () => {
  const obj = {a:1, b:2};
  return obj;
}

この違いは、式の返り値がどうなっているかの違いです!
iTerm上だと、

> {a:1, b:2}
{a:1, b:2}
> const obj = {a:1, b:2}
undefined

こんな感じになると思うのですが、変数定義の返り値はundefinedなので2文以上の場合は基本returnが必要になる。

参考:https://iwb.jp/javascript-arrow-function-omits-return-tips/

0
0
1

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
0