showing results for - "tagged templates"
Javier
02 Jan 2021
1let person = 'Mike';
2let age = 28;
3
4function myTag(strings, personExp, ageExp) {
5  let str0 = strings[0]; // "That "
6  let str1 = strings[1]; // " is a "
7  let str2 = strings[2]; // "."
8
9  let ageStr;
10  if (ageExp > 99){
11    ageStr = 'centenarian';
12  } else {
13    ageStr = 'youngster';
14  }
15
16  // We can even return a string built using a template literal
17  return `${str0}${personExp}${str1}${ageStr}${str2}`;
18}
19
20let output = myTag`That ${ person } is a ${ age }.`;
21
22console.log(output);
23// That Mike is a youngster.
24