模板字符串相当于加强版的字符串,用反引号 `,除了作为普通字符串,还可以用来定义多行字符串,还可 以在字符串中加入变量和表达式。

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