up
This commit is contained in:
parent
337a15594a
commit
cd86e9993b
10 changed files with 303 additions and 345 deletions
|
@ -0,0 +1,26 @@
|
|||
|
||||
|
||||
```js
|
||||
//+ no-beautify
|
||||
"" + 1 + 0 = "10" // (1)
|
||||
"" - 1 + 0 = -1 // (2)
|
||||
true + false = 1
|
||||
6 / "3" = 2
|
||||
"2" * "3" = 6
|
||||
4 + 5 + "px" = "9px"
|
||||
"$" + 4 + 5
= "$45"
|
||||
"4" - 2
= 2
|
||||
"4px" - 2
= NaN
|
||||
7 / 0
= Infinity
|
||||
" -9\n" + 5 = " -9\n5"
|
||||
" -9\n" - 5 = -14
|
||||
null + 1 = 1 // (3)
|
||||
undefined + 1 = NaN // (4)
|
||||
```
|
||||
|
||||
<ol>
|
||||
<li>The plus `"+"` operator in this case first converts `1` to a string: `"" + 1 = "1"`, and then adds `0`.</li>
|
||||
<li>The minus `"-"` operator only works with numbers, it converts an empty string `""` to zero immediately.</li>
|
||||
<li>`null` becomes `0` after the numeric conversion.</li>
|
||||
<li>`undefined` becomes `NaN` after the numeric conversion.</li>
|
||||
</ol>
|
|
@ -0,0 +1,26 @@
|
|||
# Type conversions
|
||||
|
||||
[importance 5]
|
||||
|
||||
Let's recap type conversions in the context of operators.
|
||||
|
||||
What will be the result for expressions?
|
||||
|
||||
```js
|
||||
//+ no-beautify
|
||||
"" + 1 + 0
|
||||
"" - 1 + 0
|
||||
true + false
|
||||
6 / "3"
|
||||
"2" * "3"
|
||||
4 + 5 + "px"
|
||||
"$" + 4 + 5
|
||||
"4" - 2
|
||||
"4px" - 2
|
||||
7 / 0
|
||||
" -9\n" + 5
|
||||
" -9\n" - 5
|
||||
null + 1
|
||||
undefined + 1
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue