Last active
October 16, 2020 16:00
-
-
Save Kannndev/19a76d00896dc71d8e96df922b4f96ff to your computer and use it in GitHub Desktop.
Tagged template sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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