Skip to content

Commit c3cd9da

Browse files
committed
Template literals (Template strings) 🚀
1 parent bded6b9 commit c3cd9da

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
console.log(`string text line 1
2+
string text line 2`);
3+
4+
let a = 9;
5+
let b = 10;
6+
console.log(`Fifteen is ${a + b} and
7+
not ${2 * a + b}.`);
8+
9+
let person = 'Lakshman';
10+
let age = 28;
11+
12+
function myTag(strings, personExp, ageExp) {
13+
let str0 = strings[0]; // "That "
14+
let str1 = strings[1]; // " is a "
15+
16+
let ageStr;
17+
if (ageExp > 99) {
18+
ageStr = 'centenarian';
19+
} else {
20+
ageStr = 'youngster';
21+
}
22+
23+
return `${str0}${personExp}${str1}${ageStr}`;
24+
}
25+
26+
let output = myTag`That ${person} is a ${age}`;
27+
28+
console.log(output);

0 commit comments

Comments
 (0)