我有以下Ecma-Script-6代码 template literals
let person = {name: 'John Smith'};
let tpl = `My name is ${person.name}.`;
let MyVar="My name is "+ person.name+".";
console.log("template literal= "+tpl);
console.log("my variable = "+MyVar);
输出如下:
template literal= My name is John Smith.
my variable = My name is John Smith.
这是小提琴。我尝试搜索确切的差异,但找不到它,我的问题是这两个语句之间有什么区别,
let tpl = `My name is ${person.name}.`;
和
let MyVar = "My name is "+ person.name+".";
我已经可以在此处将字符串MyVar串联起来person.name了,那么使用模板文字的方案是什么?
相关分类