DEV Community

Cover image for # Template Literals in javascript
Shubham Gupta
Shubham Gupta

Posted on • Updated on

# Template Literals in javascript

In a javascript, there was a different way of writing a string. the most common method is to use single and double quotes, for example

'String by a single quote'
"String by a double quote"

There was one more way through that you can write a string and that is backticks(`)

`String by a backtick`

Now why we should use this, the answer is With that syntax, you can dynamically add data into a string like this:

const city= "Pune";
const country = "India";
console.log(`My current city is ${city} and which is located in ${country});

final result:- My current city is Pune and which is located in India

There was an "old" way of concatenating strings:

"My current city is "+city+" and which is located in "+country

Top comments (0)