Last active
June 20, 2023 22:04
-
-
Save barcellos-pedro/45e6572d59c6b06e841e4e2cc5327ce8 to your computer and use it in GitHub Desktop.
Template literals - Tagged templates
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
// MDN Docs | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals | |
/** | |
* @param {string[]} value as array | |
* @param {any} val1 | |
* @param {any} val2 | |
*/ | |
function templateExample(string, val1, val2) { | |
console.log('string\n', string); | |
console.log('val 1 = ',val1); | |
console.log('val 2 = ',val2); | |
console.log(arguments); | |
return `${string[0]} ${val1} ${string[1]} ${val2} ${string[2]}`; | |
} | |
const firstName = "pedro"; | |
const age = 26; | |
const result1 = templateExample`hello i am ${firstName}, and i am ${age} yers old.`; | |
console.log(result1); | |
console.log("-".repeat(15)); | |
console.log("-".repeat(15)); | |
const result2 = templateExample`hello i am ${"firstName"}, and i am ${"age"} yers old.`; | |
console.log(result2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment