ES6中的模板字符串使用反引号 (` `) 来代替普通字符串中的用双引号和单引号。模板字符串可以包含特定语法(${expression})的占位符。
const name = '小红';
const age = 18;
console.info(`我叫${
name},今年${
age}岁`);
// 等价于
console.info('我叫' + name + ',今年' + age + '岁');
// 最大的优势是支持换行字符串
const url = '//baidu.com';
const text = '百度一下,你就知道';
const html = `
<div class="container">
<a href="${
url}">${
text}</a>
</div>
`;
console.log(html);
console.log(typeof html);