最近遇到一些使用`and'的JS代码。我不知道每个撇号是否有不同的用途。有没有?
'
或 "
表示 字符串
`
表示模板字符串。模板字符串具有普通字符串所没有的一些功能。最重要的是,你得到了插值:
var value = 123;
console.log('test ${value}') //=> test ${value}
console.log(`test ${value}`) //=> test 123
和多行字符串:
console.log('test
test')
// Syntax error
console.log(`test
test`)
// test
// test
他们还有一些其他技巧,更多关于模板字符串的信息:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings