Skip to content

Instantly share code, notes, and snippets.

@KinoAR
Last active October 16, 2016 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KinoAR/22a927b945769562fe19863009aa8f0a to your computer and use it in GitHub Desktop.
Save KinoAR/22a927b945769562fe19863009aa8f0a to your computer and use it in GitHub Desktop.
An example of template literals syntax vs ES5 strings for Endless Illusion Software ES6 features tutorial.
//Template Literals
//Multiline Strings
//ES5
var es5string = "Hello sir, welcome to our store, I'm sure you've had"
+ "\na tough day sir."
+ "\nDon't worry, we can still help you!";
//ES6
var es6string = `Hello sir, welcome to our store, I'm sure you've had
a tough day sir.
Don't worry, we can still help you!`;
// Expression Interpolation
var a = 20;
var b = 55;
var name = "Harold";
//ES5
var es5string2 = name + ": the total is " + (a + b) + ".";
//ES6
var es6string2 = `${name}: the total is ${a+b}.`;
console.log(es5string2); //Harold: the total is 75.
console.log(es6string2); //Harold: the total is 75.
//As you can see the es6 way of doing thing is a lot easier, when you want a string to span multiple lines, or
//Just want to insert variables into a string, you can even put object properties as potential variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment