Skip to content

Instantly share code, notes, and snippets.

@alvaaz
Created January 25, 2019 02:06
Show Gist options
  • Select an option

  • Save alvaaz/251022617a48d0ac056868eebcc1abe5 to your computer and use it in GitHub Desktop.

Select an option

Save alvaaz/251022617a48d0ac056868eebcc1abe5 to your computer and use it in GitHub Desktop.
Tagged template
function highlight(strings, ...values){
let str = '';
strings.forEach((string, i) => {
str += `${string} <span class="hl">${values[i] || ''}</span>`;
});
return str;
}
const name = 'Snickers';
const age = 100;
const sentence = hightlight`My dog's name is ${name} and he is ${age} years old`;
document.body.innerHTML = sentence;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment