minor
This commit is contained in:
parent
7e5ffe269e
commit
ed4878f269
2 changed files with 10 additions and 8 deletions
|
@ -10,13 +10,15 @@ true + false = 1
|
|||
"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)
|
||||
" -9 " + 5 = " -9 5" // (3)
|
||||
" -9 " - 5 = -14 // (4)
|
||||
null + 1 = 1 // (5)
|
||||
undefined + 1 = NaN // (6)
|
||||
```
|
||||
|
||||
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.
|
||||
2. The subtraction `-` (like most math operations) only works with numbers, it converts an empty string `""` to `0`.
|
||||
3. `null` becomes `0` after the numeric conversion.
|
||||
4. `undefined` becomes `NaN` after the numeric conversion.
|
||||
3. The addition with a string appends the number `5` to the string.
|
||||
4. The subtraction always converts to numbers, so it makes `" -9 "` a number `-9` (ignoring spaces around it).
|
||||
5. `null` becomes `0` after the numeric conversion.
|
||||
6. `undefined` becomes `NaN` after the numeric conversion.
|
||||
|
|
|
@ -17,8 +17,8 @@ true + false
|
|||
"4" - 2
|
||||
"4px" - 2
|
||||
7 / 0
|
||||
" -9\n" + 5
|
||||
" -9\n" - 5
|
||||
" -9 " + 5
|
||||
" -9 " - 5
|
||||
null + 1
|
||||
undefined + 1
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue