// 1、多行字符串 let string1 = `Hey, can you stop angry now?` console.log(string1) //输出格式: // Hey, // can you stop angry now?
1 2 3 4 5 6
// 2、字符串插入变量和表达式。变量名写在 ${} 中,${} 中可以放入 JavaScript 表达式。 let name = "Mike" let age = 27 let info = `My Name is ${name},I am ${age+1} years old next year.` console.log(info) // 输出:My Name is Mike,I am 28 years old next year.
1 2 3 4 5 6 7 8
// 3、字符串中调用函数 functionf(){ return"have fun!" } let string2 = `Game start,${f()}` console.log(string2); //输出: Game start,have fun!