模板字面量之变量占位符&默认参数

变量占位符可以看做是JavaScript字符串的升级版,可以将JS表达式嵌入到模板字面量中。

let name="张三"

let str=`欢迎${name}同学,学习Vue`
console.log(str)

let price=10
let amount=3

let str=`商品价格${price},商品数量${amount},总价${(amount*price).toFixed(2)}`
console.log(str)

在ES5中声明函数参数是不能有默认值的,但是在ES6中是可以写默认值的。

function getName(name="张三"){
    console.log(name)
}

getName()

猜你喜欢

转载自blog.csdn.net/qq_26798533/article/details/119419622
今日推荐