JavaScript never had a true good way to handle multiline strings, until 2015 when ES6 was introduced, along with template literals.
JavaScript从来没有一种真正的好方法来处理多行字符串,直到2015年ES6连同模板文字一起被引入。
Template literals are strings delimited by backticks, instead of the normal single/double quote delimiter.
模板文字是用反引号分隔的字符串,而不是普通的单引号/双引号定界符。
They have a unique feature: they allow multiline strings:
它们具有独特的功能:它们允许多行字符串:
const multilineString = `A string
on multiple lines`
const anotherMultilineString = `Hey
this is cool
a multiline
st
r
i
n
g
!
`
翻译自: https://flaviocopes.com/how-to-create-multiline-string-javascript/