变量替换
模板字面量允许字符串中的变量:
实例
let firstName = "Bill";
let lastName = "Gates";
let text = Welcome ${firstName}, ${lastName}!
;
亲自试一试
用真实值自动替换变量称为字符串插值。
表达式替换
模板字面量允许字符串中的表达式:
实例
let price = 10;
let VAT = 0.25;
let total = Total: ${(price * (1 + VAT)).toFixed(2)}
;