6
3

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 1 year has passed since last update.

【コードレビューTIPS】 オブジェクトキーの名前と変数名が同じ場合は省略できる

Last updated at Posted at 2022-09-09

ちょっとしたTIPSです。

  • 関数の引数として、複数の変数がまとまったオブジェクトを渡すとき
  • オブジェクトを作成するとき

などの際に、「オブジェクトキーと変数名がまったく同じ」ということがあります。
そんなときはcompanyId: companyId,というように並べるよりも、省略した方が読みやすさがアップします :thumbsup:

NG

const params = {
    companyId: companyId,
    planType: planType,
    amount: amount,
  }

OK

const params = {
    companyId,
    planType,
    amount,
  }

まとめ

レビューするときはできるだけコードはシンプルであったほうがうれしいですね。細かいTIPSではありますが、積み重ねが読みやすいコードに繋がるはずです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?