Merge pull request #875 from sawyerrken/master
modified sub headings for clarity and to avoid confusion
This commit is contained in:
commit
cc50d03e38
1 changed files with 6 additions and 7 deletions
|
@ -10,7 +10,7 @@ There are also cases when we need to explicitly convert a value to the expected
|
||||||
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>.
|
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>.
|
||||||
```
|
```
|
||||||
|
|
||||||
## To String
|
## String Conversion
|
||||||
|
|
||||||
String conversion happens when we need the string form of a value.
|
String conversion happens when we need the string form of a value.
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ alert(typeof value); // string
|
||||||
|
|
||||||
String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes `"null"`, etc.
|
String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes `"null"`, etc.
|
||||||
|
|
||||||
## To Number
|
## Numeric Conversion
|
||||||
|
|
||||||
Numeric conversion happens in mathematical functions and expressions automatically.
|
Numeric conversion happens in mathematical functions and expressions automatically.
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ alert( '1' + 2 ); // '12' (string to the left)
|
||||||
This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers.
|
This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers.
|
||||||
````
|
````
|
||||||
|
|
||||||
## To Boolean
|
## Boolean Conversion
|
||||||
|
|
||||||
Boolean conversion is the simplest one.
|
Boolean conversion is the simplest one.
|
||||||
|
|
||||||
|
@ -124,14 +124,13 @@ alert( Boolean(" ") ); // spaces, also true (any non-empty string is true)
|
||||||
```
|
```
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
|
|
||||||
The three most widely used type conversions are to string, to number, and to boolean.
|
The three most widely used type conversions are to string, to number, and to boolean.
|
||||||
|
|
||||||
**`To String`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
|
**`String Conversion`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
|
||||||
|
|
||||||
**`To Number`** -- Occurs in math operations. Can be performed with `Number(value)`.
|
**`Numeric Conversion`** -- Occurs in math operations. Can be performed with `Number(value)`.
|
||||||
|
|
||||||
The conversion follows the rules:
|
The conversion follows the rules:
|
||||||
|
|
||||||
|
@ -142,7 +141,7 @@ The conversion follows the rules:
|
||||||
|<code>true / false</code> | `1 / 0` |
|
|<code>true / false</code> | `1 / 0` |
|
||||||
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. |
|
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. |
|
||||||
|
|
||||||
**`To Boolean`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
|
**`Boolean Conversion`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
|
||||||
|
|
||||||
Follows the rules:
|
Follows the rules:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue