Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I still get bitten by

> [] == []

< false

sometimes. And that's with two equal signs, not three!




Two separate references to two separate arrays equaling false? What's the problem?


When doing functional programming, immutable lists with value comparison are what you want. However with JS, you only get mutable arrays with reference equality out-of-the-box. You can use a library, as others have point out, but then your code gets very noisy.


JS has a very "unique" opinion that that is how that should be interpreted. Given the same input as above:

Python says True.

Ruby says true.

JS says false.

And otherwise, JS is quite lenient with not interpreting the input like you describe it when using "==":

> [] == 0

< true

> [] == false

< true




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: