4 ms·
Writing literal [] + []? No. Writing x + y where x and y are both arguments to a function, and some call site was passed an (empty?) array of integers instead
by lmkg 12y ago
Writing literal [] + []? No.
Writing x + y where x and y are both arguments to a function, and some call site was passed an (empty?) array of integers instead of an integer? Believable.
- untog 12y agoI've been writing JS professionally for, what, a decade now - and I've never once had this issue.
- wal0 12y agoIt's not about this causing issues IMO. It's just.. why? Why would '+' not be commutative? Why not throw an error? What is the use-case for "adding" '[]' and '{}'? Or, put another way: why would a programmer want to have this "feature" instead of being notified: "hey, you're adding '[]' and '{}', that doesn't make any sense, fix that!" Sure you can work with a language like that. But it sure doesn't feel like somebody thought all of this this through.
- path411 12y agoSo the real problem is passing wrong parameters to a function? Sounds like you should swap to something like TypeScript for strict typing then. Or you know, stop acting like JavaScript is unique in that improper function calling breaks your code. I can't believe in 2015 there are still people who follow the "JavaScript equalities are WTF" mentality. If you are running into equality operator problems in JS, you are probably going to run into a myriad of problems in any language.
- untitaker_ 12y agoExcept in any decent language, however typed, improper function calling creates errors. I can't believe in 2015 there are still people who follow the "invalid input should produce invalid output" mentality.