ES2015 (ES6) Template Strings

Example: https://jsfiddle.net/ehdgpvyb/

ES2015 provides a better way to use variables inside strings.


function exampleJS5( name , age ) {
console.log("Hello " + name + ", you are " + age + "!");
}

function exampleJS6( name , age ) {
console.log(`Hello ${name}, you are ${age}!`);
}

exampleJS5('Bob', 20);
//Hello Bob, you are 20!
exampleJS6('Bob', 20);
//Hello Bob, you are 20!

Advertisements