es6 string interpolation code example
Example 1: typescript string interpolation
let playerName:string = "Sachin Tendulkar";
console.log(`${playerName} is the greatest cricketer of all time`)
Example 2: string interpolation javascript
const age = 3
console.log(`I'm ${age} years old!`)
Example 3: javascript string interpolation
var animal = "cow";
var str=`The ${animal} jumped over the moon`;
Example 4: string literal javascript
`string text`
`string text line 1
string text line 2`
`string text ${expression} string text`
tag`string text ${expression} string text`
Example 5: template string in typescript
let lyrics = 'Never gonna give you up';
let html = `<div>${lyrics}</div>`;
Example 6: #{} js
let value = dummy`Ik ben ${name} en ik ben ${age} jaar`;
function dummy() {
let str = "";
strings.forEach((string, i) => {
str += string + values[i];
});
return str;
}