Skip to content

Commit 57ac5da

Browse files
committed
Template Literals
1 parent 681aa88 commit 57ac5da

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

06. Template Literals/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<h1 id="showMessage"></h1>
10+
<!-- link javacript file -->
11+
<script src="js/script.js"></script>
12+
13+
</body>
14+
</html>

06. Template Literals/js/script.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Template Literals(New Feature of ES6)
2+
// Backtick ``
3+
// Template Strings use back-ticks (``) rather than the quotes ("") to define a string:
4+
// Template Strings allow both single and double quotes inside a string:
5+
console.log(`Hello, "Aktaruzzaman"`);
6+
console.log(`Hello, 'Aktaruzzaman'`);
7+
8+
// Template Strings allow multiline strings:
9+
let text = `I wanna write a poems
10+
But I have no coins
11+
How can publich poems
12+
Give me some coins for writing poems`;
13+
14+
console.log(text);
15+
16+
// Interpolation
17+
// Template String provide an easy way to interpolate variables and expressions into strings. The method is called string interpolation.
18+
19+
// The syntax is: ${..}
20+
21+
// Variable Substitutions: Template Strings allow variables in strings:
22+
let fisrtName = 'Aktaruzzaman';
23+
let middleName = "Al";
24+
let lastName = "Fatih";
25+
26+
console.log(`Name: ${fisrtName} ${middleName} ${lastName}`);
27+
28+
let a = 10;
29+
let b = 20;
30+
31+
console.log(`${a} + ${b} = ${a + b}`);
32+

0 commit comments

Comments
 (0)