JavaScript Introduction


Template Literals act like strings with special features. They are enclosed by by the back-tick `` and can be spanned across multiple lines.

Template Literals can contain embedded expressions too. These expressions are indicated by a $ sign and curly braces {}

//A single line Template Literal  
var aLiteral = `single line string data`;

//Template Literal that spans across lines       
var anotherLiteral = `string data that spans
         across multiple lines of code`;     

//Template Literal with an embedded expression
var x = 2;
var y = 3; 
var theTotal = `The total is ${x + y}`;     // Contains "The total is 5" 

//Comarison of a string and a template literal
var aString = "single line string data"
console.log(aString === aLiteral)                         //Returns true

There are many other features of String Literals such as Tagged Template Literals and Raw property. These are demonstrated in other examples.