1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

テンプレートリテラル`${}`でコードの可読性が上がる

Posted at

多くの場合、console.logでコメントを出す際には、変数が含まれていると思います。
その際に

log
const name = Tom;
console.log("Hello, " + name);

などと書いていないでしょうか?
初歩的なことですが、

log
const name = Tom;
console.log(`Hello, ${name}`);

と書くと、可読性が上がります!変数を{}で括って、$を付けるだけです。
文字列を括るのは"や'ではなく、`(SHIFT+@で出ます)であることに気を付けてください。
たった二行のコードだと、その便利さは分かりませんが、長いコードを書くと、いちいち"+"でつなぐ記法だと読みづらくて仕方ありません。
積極的に`${}`を使っていきましょう。

1
0
3

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?