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
1010" 4" - 2 = 2
1111" 4px" - 2 = NaN
12127 / 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 )
1717```
1818
19191 . The addition with a string ` "" + 1 ` converts ` 1 ` to a string: ` "" + 1 = "1" ` , and then we have ` "1" + 0 ` , the same rule is applied.
20202 . 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
1717" 4" - 2
1818" 4px" - 2
19197 / 0
20- " -9\n " + 5
21- " -9\n " - 5
20+ " -9 " + 5
21+ " -9 " - 5
2222null + 1
2323undefined + 1
2424```
You can’t perform that action at this time.
0 commit comments