Hi, I am Kiru 👋 an indie hacker, a problem solver and vim-lover. I build projects to make the life of others and mine easier.

This page is intended to collect all my projects and some thoughts.

Tagged Templates in JavaScript

TIL 25.05.2021

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"]

Learn more: