テンプレート文字列
3501 ワード
テンプレート文字列について学習していきます。
テンプレート文字列とは、バックティックで囲んだ文字列の事を言います。
`${ 変数 }`
上記のように記述します。
できることは、以下になります。
① 変数の値を文字列に埋め込むことができる
② 改行をすることができる
③ 式を文字列に埋め込むことができる
① 変数を文字列に埋め込む事ができる
index.js
<script>
'use strict'
let language = "こんにちわ";
document.write(`皆さん${language}!!`);
</script>
index.js
<script>
'use strict'
let language = "こんにちわ";
document.write(`皆さん${language}!!`);
</script>
② 改行をすることができる
index.html
<script>
document.write(`あいうえお
かきくけこ`);
</script>
index.html
<script>
document.write(`あいうえお
かきくけこ`);
</script>
③ 式を文字列に埋め込むことができる
index.html
<script>
let name = "とんかつ定食";
let price = 400;
let msg =`今日の${name}は${price * 1.08}円です!!`;
document.write(msg);
</script>
index.html
<script>
let name = "とんかつ定食";
let price = 400;
let msg =`今日の${name}は${price * 1.08}円です!!`;
document.write(msg);
</script>
Author And Source
この問題について(テンプレート文字列), 我々は、より多くの情報をここで見つけました https://qiita.com/akari_0618/items/ebb3c957ac2e9b90a9b8著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .