模板字符串

131 阅读1分钟

模板字符串

模板语法 在字符串输出变量的值
var name = 'jack'
`hello:${name}`='hello:jack'
${变量}

在模板语法中可以进行简单运算
${a+b}
${true?'hello':'world'}
function text(){
           var name='jack'
           var str=`hello:${name}`
           console.log(str);
       }
    //    text()

    function text1(){
           var a=10
           var b=20
           var str=`${a}+${b}=${a+b}`
           console.log(str);
       }
    //    text1()
       function text2(){
        var name='jack'
          
           console.log(str);
       }
       //text2()