khushbu Pathe
PRO
last month
Khushbucountry asked

What are template literals in JavaScript?

Abhay Jajodia
Expert
last month
Abhay Jajodia answered

Template literals are another way to write strings in JavaScript using backticks instead of quotes. The helpful thing about them is that you can drop variables straight into the string without breaking it apart.

Here’s a full example so you can see it in action:

let name = "Hushbu";
let city = "Mumbai";

let message = `Hi ${name}, you live in ${city}. Nice to meet you!`;

console.log(message);

When you run it, you’ll get:

Hi Hushbu, you live in Mumbai. Nice to meet you!

You can also make multi-line strings with template literals, which keeps things easy to read.

If anything here feels unclear or you want more examples, I’m here to help.

JS
This question was asked as part of the Learn JavaScript Basics course.