Skip to content

Instantly share code, notes, and snippets.

@Kannndev
Last active October 16, 2020 16:00
Show Gist options
  • Save Kannndev/19a76d00896dc71d8e96df922b4f96ff to your computer and use it in GitHub Desktop.
Save Kannndev/19a76d00896dc71d8e96df922b4f96ff to your computer and use it in GitHub Desktop.
Tagged template sample
const generateIntro = (strings, ...values) => {
console.log(strings); // [ 'My name is ', ' and I am a ', '' ]
console.log(values); // [ 'Kannan', 'Javascript developer' ]
let str = '';
strings.forEach((string, i) => {
str += string + (values[i] || '');
});
return str;
}
const name = 'Kannan';
const role = 'Javascript developer';
generateIntro`My name is ${name} and I am a ${role}`;
// My name is Kannan and I am a Javascript developer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment