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/02-first-steps/06-type-conversions/article.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ There are also cases when we need to explicitly convert a value to the expected
10
10
In this chapter, we won't cover objects. Instead, we'll study primitives first. Later, after we learn about objects, we'll see how object conversion works in the chapter <info:object-toprimitive>.
11
11
```
12
12
13
-
## To String
13
+
## String Conversion
14
14
15
15
String conversion happens when we need the string form of a value.
16
16
@@ -30,7 +30,7 @@ alert(typeof value); // string
30
30
31
31
String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes `"null"`, etc.
32
32
33
-
## To Number
33
+
## Numeric Conversion
34
34
35
35
Numeric conversion happens in mathematical functions and expressions automatically.
36
36
@@ -94,7 +94,7 @@ alert( '1' + 2 ); // '12' (string to the left)
94
94
This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers.
95
95
````
96
96
97
-
## To Boolean
97
+
## Boolean Conversion
98
98
99
99
Boolean conversion is the simplest one.
100
100
@@ -124,14 +124,13 @@ alert( Boolean(" ") ); // spaces, also true (any non-empty string is true)
124
124
```
125
125
````
126
126
127
-
128
127
## Summary
129
128
130
129
The three most widely used type conversions are to string, to number, and to boolean.
131
130
132
-
**`To String`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
131
+
**`String Conversion`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
133
132
134
-
**`To Number`** -- Occurs in math operations. Can be performed with `Number(value)`.
133
+
**`Numeric Conversion`** -- Occurs in math operations. Can be performed with `Number(value)`.
135
134
136
135
The conversion follows the rules:
137
136
@@ -142,7 +141,7 @@ The conversion follows the rules:
142
141
|<code>true / false</code> | `1 / 0` |
143
142
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. |
144
143
145
-
**`To Boolean`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
144
+
**`Boolean Conversion`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
0 commit comments