Live data from Hacker News

In JavaScript, why does (null + null === 0) return true?

news.ycombinator.com

1–5 of 5 posts

Re: In JavaScript, why does (null + null === 0) return true?

#3
I don't really know (I don't have that in depth knowledge of javascript) but it is probably like you said, because you are doing a sum, it treats null as 0, so (0 + 0 === 0) is true.

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