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