1
0

【Javascript】テンプレートリテラル(テンプレート文字列)

Posted at

文字列の中に式や変数を埋め込むことができる

書き方
var name = "ペンギン";
var age = 30;

console.log("こんにちは。私は" + name + "です。" + age + "歳です。");



console.log(`こんにちは。私は${name}です。${age}歳です。`);
こんにちは。私はペンギンです。30歳です。

改行文字がそのまま改行として扱われる

書き方
var msg = `こんにちは。
私はペンギンです。
30歳です。`;

console.log(msg);
こんにちは。
私はペンギンです。
30歳です。
1
0
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
1
0