Tagged Templates in JavaScript
JavaScript supports template strings since ES2015:
const me = "Kiru"
const missing = 22/7 - Math.PI
console.log(`Print var: ${me} and ${missing}`)
console.log(`This also works: ${22/7} - ${Math.PI} = ${missing}`)
You can pass the tagged templates to functions:
function printTemplates(strings, ...keys) {
console.log("Strings: ", strings);
console.log("Keys", keys);
}
printTemplates`What is possible: ${me}`
Will print:
Strings: ["What is possible: ", "", raw: Array(2)]
Keys ["Kiru"]