Skip to content

模板字符串

模板字符串 引入新的声明字符串的方式

一、声明

js
let str = `hello world`
console.log(str, typeof str)

二、特性

  • 模板字符串可以换行,并且可以包含换行符 \n
  • 模板字符串可以包含变量 ${变量名}
  • 模板字符串可以包含表达式 ${表达式}
  • 模板字符串可以包含函数 ${函数名()}
  • 模板字符串可以包含对象 ${对象名}
  • 模板字符串可以包含数组 ${数组名}
  • 模板字符串可以包含正则表达式 ${/正则表达式/}
  • 模板字符串可以包含注释 ${/* 注释 */}
  • 模板字符串可以包含转义字符 ${\n}

Released under the MIT License.