|
|
|
In JavaScript, why does (null + null === 0) return true?
|
|
1 points
by swozniak
4431 days ago
|
|
I could be convinced into thinking == would return true if null was treated as 0 (so 0 + 0 = 0), but with ===, this doesn't seem right at all, especially considering: typeof null === 'object' and typeof 0 === 'number' Can someone explain? |
|
You can do the same with false: (false + false === 0)
And also (true + true === 2) is true
Edit: The same way as if you do "" + 1 you get "1" because it assumes + as string concatenation