es6字符串拼接


//包含变量或表达式

const a = 10

const b = 20

const c = 'html'

const str = `my age is ${a + b} i love ${c}`

//包含逻辑运算的用法

function Price (strings,type){

   let s1 = strings[0]

   const retailPrice = 20

   const wholeSalePrice = 16

   let showTxt

   if(type === 'retail'){

       showTxt = '购买单价是:' + retailPrice

   }else{

       showTxt = '购买的批发价是:' + wholeSalePrice

   }

   return `${s1}${showTxt}`

}

let showTxt = Price`你此次的${retail}`

console.log(showTxt)

//换行写法

let s = `第一行

第二行`

console.log(s)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM