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
Copy file name to clipboardExpand all lines: 1-js/2-first-steps/7-types-intro/article.md
+21-2Lines changed: 21 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,16 +43,35 @@ We'll cover working with numbers in the chapter [](/number).
43
43
```js
44
44
var str ="Hello";
45
45
var str2 ='Single quotes are ok too';
46
-
varprase=`can embed ${str}`;
46
+
varphrase=`can embed ${str}`;
47
47
```
48
48
49
49
In JavaScript, there are 3 types of quotes.
50
50
51
51
<ol>
52
-
<li>Double quotes and single quotes are essentially the same.</li>
52
+
<li>Double quotes: `"Hello"`.</li>
53
+
<li>Single quotes: `'Hello'`.</li>
53
54
<li>Backtricks are "extended functionality" quotes. They allow to embed other variables or even expressions into the string wrapping them by `${…}`.</li>
54
55
</ol>
55
56
57
+
Double and single quotes are essentially the same. The only difference between them can be seen when the string includes the quotation character `"` or `'`.
58
+
59
+
A double quote symbol may appear inside single-quoted lines and vise versa:
60
+
61
+
```js
62
+
var hello ="I'm JavaScript"; // single-quote inside "…"
63
+
var name ='My "official" name is "EcmaScript"'; // vise versa
64
+
```
65
+
66
+
If we want to include a single quote inside a same-quoted string, we can do it too. But we need to prepend it with a slash:
67
+
68
+
```js
69
+
// prepend ' inside the string with a slash \'
70
+
var hello ='I\'m JavaScript';
71
+
```
72
+
73
+
Similarly with double quotes.
74
+
56
75
[smart header="There is no *character* type."]
57
76
In some languages, there is a special "character" type for a single character. For example, in the C language it is `char`.
0 commit comments