-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14 templete string.js
More file actions
80 lines (55 loc) · 1.58 KB
/
14 templete string.js
File metadata and controls
80 lines (55 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
JavaScript Template Literals
Synonyms:
Template Literals
Template Strings
String Templates
Back-Tics Syntax
Back-Tics Syntax
Template Literals use back-ticks (``) rather than the quotes ("") to define a string:
*/
var text=`RANA ABOBAKAR SAB KYA HAL HA RANA`;
/*
*********Quotes Inside Strings**************
With template literals, you can use both single and double quotes inside a string
*/
var text=`RANA' ABOBAKAR "SAB" KYA HAL HA RANA`;
// ************Multiline Strings**************
// Template literals allows multiline strings:
var text =
`The quick
brown fox
jumps over
the lazy dog`;
/*
********************Interpolation*********************
Template literals provide an easy way to interpolate variables and expressions into strings.
The method is called string interpolation.
The syntax is:
${...}
-******************Variable Substitutions************
Template literals allows variables in strings:
*/
var firstName = "RANA";
var lastName = "ABOBAKAR";
var text = `Welcome ${firstName}, ${firstName}`;
console.log(text);
//Automatic replacing of variables with real values is called string interpolation.
/*
Expression Substitution
Template literals allows expressions in strings:
*/
let price = 10;
let VAT = 0.25;
let total = `Total: ${(price * (1 + VAT)).toFixed(2)}`;
console.log(total);
/*
***************HTML Templates***************
let header = "Templates Literals";
let tags = ["template literals", "javascript", "es6"];
let html = `<h2>${header}</h2><ul>`;
for (const x of tags) {
html += `<li>${x}</li>`;
}
html += `</ul>`;
*/