Introduction

suggest change

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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Template Literals:
* Syntax
* Introduction

Table Of Contents
10 Template Literals
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde