JavaScript Template Strings

String Interpolation

String Interpolation is the way by which we can insert variable into string. In Javascript We have two type for String Interpolation.

1. Traditional
2. ES6

1. Traditional Way

In traditional Javascript, string always encolsed within ” or ‘. Using double or single quotes we can write text on one line. There was no way to insert data into these strings. This kind of way looks very ugly.


var name = "xyz";
var age = 40;

console.log("Welcome " + name + " You are looking " + age + " years old"); 
//Welcome xyz You are looking 40 years old

2. ES6 Way

In Es6 we have new type of string literal that is marked with back ticks (`). Here we can write text new line as wel as we can insert data in between text string.


var name = "xyz";
var age = 40;

console.log(`Welcome ${name} You are looking ${age} years old`); 
// Welcome xyz You are looking 40 years old

You May Also Like

About the Author: Pankaj Bisht