字符串内插被识别为字符串。
let highScore = 1430;
let userScore = 1600;
if (userScore >= highScore) {
console.log("Congrats, you have the new high score of ${userScore}");
}
JavaScript仅支持使用反引号的模板文字中的字符串替换
let userScore = 1430;
let string1 = "Congrats, you have the new high score of ${userScore}";
let string2 = `Congrats, you have the new high score of ${userScore}`;
document.querySelector('#result1').textContent = string1;
document.querySelector('#result2').textContent = string2;
<pre id="result1"></pre>
<pre id="result2"></pre>
注意console.log
itself does some substitutions。浏览器显然有所不同。