字符串的反引号
重要程度: 5
下面的脚本会输出什么?
let name = "Ilya"; alert( `hello ${1}` ); // ? alert( `hello ${"name"}` ); // ? alert( `hello ${name}` ); // ? 反引号将包装在 ${...} 中的表达式嵌入到了字符串。
let name = "Ilya"; // 表达式为数字 1 alert( `hello ${1}` ); // hello 1 // 表达式是一个字符串 "name" alert( `hello ${"name"}` ); // hello name // 表达式是一个变量,嵌入进去了。 alert( `hello ${name}` ); // hello Ilya