Template Literals in JavaScript

This is a modern way to define string it introduce with JavaScript ES6 features. Now its become standard for dealing with complex string manipulation because of this it become foundation concept wh...

By · · 1 min read

Source: dev.to

This is a modern way to define string it introduce with JavaScript ES6 features. Now its become standard for dealing with complex string manipulation because of this it become foundation concept which every developer should know it. In this article we discussing what it is? how syntax look like? and what is the use case of it? Problems with traditional string concatenation In early developers use single (') and double (") quotes to define string. With this if they need to add variable with string they need to use (+) operator to do this, called string concatenation. This approach work well but if there are many variables then it becomes massy and hard to read or manage it. But with template literals its easy to add any number of variables directly within the string, no need concatenation here. This approach is good for work with dozens of variables and also provide good readability. const name = "Anoop" const age = 20 // old way console.log("Hello my name is " + name + " and i am " + a