首页 > 其他 > 详细

es6字符串拼接

时间:2020-01-18 21:53:37      阅读:71      评论:0      收藏:0      [点我收藏+]

//包含变量或表达式

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)

es6字符串拼接

原文:https://www.cnblogs.com/qjb2404/p/12210236.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!