Template strings support interpolation! This means you could write a variable in your string, and get its value. The syntax is straightforward, you simply wrap your variable name with a dollar sign and curly braces. Let's take an example where we have a variable language with a value of JavaScript.
const language = 'javascript';
I am learning ${language}
; //"I am learning JavaScript"; (get the output)
1-A template string is a string created with the backtick character: `
2-Template strings can span multiple lines
3-Template strings support interpolation with the ${variableName} syntax
//How to interpolate in JavaScript
const name = "John";
console.log(Welcome ${name}. You have ${2 * 5} new notifications!
);
const wes = new Object({
name: "wes",
propertyToCheck: "NEVER",
age,
"cool-dude": true,
"really cool": false,
"777": true,
dog: "snickers",
clothing: {
shirts: 10,
pants: 2
},
sayHello: function(greeting = "Hey") {
return ${greeting} ${this.name}
;
}
});