Wednesday, September 11, 2019

[JS][Example] JavaScript ES6 feature : Template Literals

ECMAScript 6 :
let name = "Sam";
let age = "45";
let str = `I am ${name} and I am ${age} years old.`
console.log(str);
Result is I am Sam and I am 45 years old.

Script write by ECMAScript 2015:
var name = "Sam";
var age = "45";
var str = "I am ".concat(name, " and I am ").concat(age, " years old.");
console.log(str);
Remark: beware you must use the symbol `, not " or '

No comments :

Post a Comment