我有以下Ecma-Script-6代碼 template literalslet 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了,那么使用模板文字的方案是什么?
ES6模板文字與串聯字符串
哈士奇WWW
2019-12-02 09:50:32