You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- single quotes and double quotes are the same thing.
23
+
24
+
used for:`"she's cool"`
25
+
26
+
or escaping:`'she\\'s cool'`
27
+
28
+
- backticks:
29
+
30
+
```javascript
31
+
const sentence = `she's so "cool"`;
32
+
console.log(sentence); // she's so "cool"
33
+
34
+
```
35
+
36
+
- Multi-line string:
37
+
38
+
```javascript
39
+
const song = 'Oh \\
40
+
I like \\
41
+
pizza';
42
+
43
+
console.log(song); // Oh I like pizza
44
+
45
+
```
46
+
47
+
```javascript
48
+
const song = `Oh
49
+
I like
50
+
pizza`;
51
+
52
+
console.log(song);
53
+
/*
54
+
Oh
55
+
I like
56
+
pizza
57
+
*/
58
+
59
+
```
60
+
61
+
2nd one using backticks is mostly used.
62
+
63
+
-**String concatenation and interpolation**
64
+
65
+
-'+' is used for**concatenation**. It is also used for adding 2 nos.
66
+
-**Concatenation**: when 2 or more strings combined to one
67
+
-**Interpolation**: when you put a variable inside a string
68
+
- Example 1:
69
+
70
+
`const name = 'Soumya';`
71
+
72
+
`const hello = 'Hello my name is ' + name + '. Nice to meet you.'`
73
+
74
+
_(can use double or single quotes)_
75
+
76
+
- Example 2:
77
+
78
+
` 1+1 // 2`
79
+
80
+
`'1'+'1' // 11 `
81
+
82
+
`1 + '1' // 11`
83
+
84
+
- Example 3:
85
+
86
+
constname='Soumya'; consthello=`Hello my name is ${name}. Nice to meet you. I am ${100+1} years old.`; console.log(hello); // Hello my name is Soumya. Nice to meet you. I am 101 years old.
87
+
88
+
- Backticks also used for _tagged template literals_.
0 commit comments