44. What are template literals in JavaScript? Can they be used for string interpolation?
easy
Template literals in JavaScript are a way of creating strings using backticks (`) instead of quotes. They were introduced in ECMAScript 2015 (ES6) and have become a popular way of creating dynamic strings in JavaScript.

Template literals allow for string interpolation, which is a way of inserting variables or expressions into a string. This can be done using template expressions, which are embedded inside the backticks. Here's an example:
const name = 'John';
const message = `Hello, ${name}!`;
console.log(message);
// Output: "Hello, John!"
In this example, we define a variable `name` and use it in a template literal to create a personalized greeting message. The `${}` syntax is used to insert the value of the `name` variable into the string.

Template literals can also be used with expressions, which allow you to evaluate an expression inside the backticks and use its result as part of the string. Here's an example:
const age = 30;
const message = `You are ${age} years old.`;
console.log(message);
// Output: "You are 30 years old."

In this example, we define a variable `age` and use it in a template literal to create a personalized message that includes the user's age.

Template literals can also be used with destructuring assignment to extract values from arrays or objects and use them in the string. Here's an example:
const [firstName, lastName] = ['John', 'Doe'];
const message = `Hello, ${firstName} ${lastName}!`;
console.log(message);
// Output: "Hello, John Doe!"

In this example, we define an array of names and use destructuring assignment to extract the first and last names. We then use these values in a template literal to create a personalized greeting message.

Overall, template literals provide a convenient way of creating dynamic strings in JavaScript using string interpolation and expressions. They can be used with variables, expressions, and destructuring assignment to create personalized messages or other dynamic content.