Hacker News new | past | comments | ask | show | jobs | submit login

Javascript when doing operations between to variables will try to coerce them into the strongest type that both support... in your example that is String, in this case ({}).toString() == "[object Object]" ... which is why you get the result. Your not understanding how a system works is not an error in the system.

What would you expect in your example? A deep copy/merge, a shallow copy/merge... right merged with left and result returned?




While the results are definitely deterministic, and play by a set of rules, most people don't bother learning these rules. This can lead to bugs in programs, if people do not take proper care. Since weak-typing doesn't give me any features, and could be a source of bugs in my program, I prefer to use languages that don't use it.


It's not even an issue in languages (C) that don't strongly type for performance reasons, or because you get closer hardware access as a result (though these count as features themselves). The problem is that in Javascript, you don't get either of these -- there's no benefits, there are only new bug vectors. This wouldn't be as big of an issue if the default coercion behaviour was generally helpful, but it's not. It's just a pain.


> what would you expect?

I expect a type error, like I said before. Implicit coercion between types is the definition of weak typing, and is part of what separates Python from Javascript.




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

Search: