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

The only problem here was that a for/in loop was being used. Iterating the array, rather than its properties, was clearly what was actually wanted. However, the author uses the opportunity to take a strong stance in favour of always using strict equals, even though it was never a bug here anyway. As far as I can see, the only argument this article produces against double equals is that overzealous developers might accidentally break your code trying to be proactive.

Strict equals is something I only use when necessary in javascript. Despite the "taboo" surrounding double equals, I rarely face situations where its use adds brittleness to the code. Is there some horrible danger that I am just not seeing?



Well in this case, the original author was relying on '0' == 0 for their code to work. Even if you were dead set against using strict equality (which is silly, but whatever), the code is still disingenuous and should have tested index == '0' to make its intent clear. There's no other value that they could have being relying on it to coerce without some other very nasty things going on.

> overzealous developers might accidentally break your code trying to be proactive

It's not just people changing your code, it's people trying to read your code (including you, months later).




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

Search: