ES6 ${}语法(转载)

序言

这是 ES6 的 Template Strings 模版字符串
就是用占位符的方式来拼接字符串

示例

const name = '小缘'
const age = 14
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)

最后

原文献的地址为:

posted @ 2021-02-28 16:09  DAmarkday  阅读(755)  评论(0编辑  收藏  举报