File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed
1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -10,13 +10,15 @@ true + false = 1
10
10
" 4" - 2 = 2
11
11
" 4px" - 2 = NaN
12
12
7 / 0 = Infinity
13
- " -9\n " + 5 = " -9\n 5 "
14
- " -9\n " - 5 = - 14
15
- null + 1 = 1 // (3 )
16
- undefined + 1 = NaN // (4 )
13
+ " -9 " + 5 = " -9 5 " // (3)
14
+ " -9 " - 5 = - 14 // (4)
15
+ null + 1 = 1 // (5 )
16
+ undefined + 1 = NaN // (6 )
17
17
```
18
18
19
19
1 . The addition with a string ` "" + 1 ` converts ` 1 ` to a string: ` "" + 1 = "1" ` , and then we have ` "1" + 0 ` , the same rule is applied.
20
20
2 . The subtraction ` - ` (like most math operations) only works with numbers, it converts an empty string ` "" ` to ` 0 ` .
21
- 3 . ` null ` becomes ` 0 ` after the numeric conversion.
22
- 4 . ` undefined ` becomes ` NaN ` after the numeric conversion.
21
+ 3 . The addition with a string appends the number ` 5 ` to the string.
22
+ 4 . The subtraction always converts to numbers, so it makes ` " -9 " ` a number ` -9 ` (ignoring spaces around it).
23
+ 5 . ` null ` becomes ` 0 ` after the numeric conversion.
24
+ 6 . ` undefined ` becomes ` NaN ` after the numeric conversion.
Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ true + false
17
17
" 4" - 2
18
18
" 4px" - 2
19
19
7 / 0
20
- " -9\n " + 5
21
- " -9\n " - 5
20
+ " -9 " + 5
21
+ " -9 " - 5
22
22
null + 1
23
23
undefined + 1
24
24
```
You can’t perform that action at this time.
0 commit comments